Create a html window within another html window - javascript

I currently have a page with a few buttons. When I click on the button I want to open a new html page within the parent page. I want to do this in such a way that the parent window becomes transparent and the new page is over it. How can I go about doing this? I have tried to use Iframes but it does not give me the output that I want.

James Kirsch has given you one way to do it. Another is to have a hidden DIV that you show when you need it. In both cases, you may have to place a semi-transparent GIF image behind the DIV (or opened window) so someone can not do anything with the rest of the web page until they have finished interacting with the new window. You can do this by using the z-index CSS command. So the DIV would be:
<DIV style='z-index:100;'>....</DIV>
and the image would be something like
<img src="PUT YOUR PATH HERE" style='position:absolute;top:0%;left:0%;width:100%;height:100%;z-index:50;'>
This would put the GIF image halfway between the web page and the DIV.
The above is what is happening when you go to a website and they grey out everything behind the new window. It also keeps people from pushing on buttons when you don't want them to do so.
IFRAME stands for something like INSERTED_FRAME where the "INSERTED" part means it is inserted into your pre-existing web page. That is why it doesn't work. Neither will the FRAME command work because (again) it is embedded into the pre-existing web page. You are wanting to lay the new window on top of the web page. Thus, Mr. Kirsch' answer and my own. Note that you can also use a TABLE command to do the same thing - even if it is frowned upon to use tables presently. It is the STYLE part of the command that causes the HTML element to appear above the rest of the web page and not any particular HTML command itself. Also, the "position:absolute" part of the STYLE command is what overrides the web page's positioning of the element. Have fun!

In the Javascript have you considered using the following?
window.open();
This call appears to take parameters for Position and Size, you may be able to close the previous window also if you desire, or manipulate it.
Example:
window.open('this.html','','left=15,top=15,width=800,height=600');
Reference: here

Related

Removing focus from embedded Issuu content on page load

I'm embedding various content from Issuu on a web page. On page load the embedded content from Issuu is automatically in focus, with visible menus and shadows within the embedded iframe.
This seems to be the standard solution, and there's no way to prevent this with the given embed codes from Issuu. But I would really like to find a way to load the content without it being in focus before the user actually hovers/clicks the embedded area.
As of now the initial focus is only removed if I first click somewhere within the embedded content, and then move my pointer outside of the content.
Is there any way to sort this out with the help of jQuery?
I have tried to solve this by adding the following jQuery code:
$('#issuu_embed').blur();
I also tried to simulate a click on the embedded iFrame, in an attempt to replicate the behaviour mentioned above.
But neither does the trick, and I assume it takes a slightly more sophisticated piece of code to make this work.
Grateful for any hints that could point me in the right direction.
Live CodePen:
https://codepen.io/ehrogn/pen/PoEmJKv

Scroll bar stays in same position from one website to another

I want to be able to click on a link in my HTML website and when I load onto the other website to be in the same position. Say you are in the middle of a website when you click the link I want to be in the middle of the website when I load onto that link. Is there anyway to do this? Sorry if this is confusing.
I'm sorry for the confusion, but I meant if you controlled both web pages. My bad.
There's no way unless you have control over the linked site.
Scrollbar is rendered by the browser based on overflow-x or overflow-y attributes, if you have no control over the linked site's code, you can't force it to present a scrollbar or scroll to a specific position(which requires javascript code to be executed)
If you have access to the linked site's code, you can send the ID of the element you want to scroll to through the url as a parameter like this:
https://example.net#mydiv
and then, at the linked site, just add this javascript code to scroll to the element:
$(window).load(() => {
const divID = window.location.hash;
document.getElementById(divID).scrollIntoView();
});

To Grey Out the WHOLE Website when you click button inside Iframe contained in that website

I know how to grey out (adding grey color) to the whole website by a click of a button using css .
But here is an interesting scenario. I have a small IFrame embedded in the main website. Inside the Iframe I have a button. On-click the button I need to grey out the entire website. Currently I am only able to grey out the IFrame contents and not the entire website. If somebody can help me regarding this that would be great.
IFrame contents are on the same domain as the website but on different paths. For example if the website is xyz.com, the iframe contents displayed on that website are in xyz.com/cms.
Note: I only have access to the code sitting inside IFrame and not the outside bit. Hence I cannot code outside IFrame. Whatever I need to code I have to do it inside the IFrame.
Can't we do anything to window object to grey out the entire window?
I think setting the grey to when the iframe window has focus may work for you.
You didn't include any code so not sure if you're using jQuery, but try something like this.
while($(iframe).focus()){
$('document').addClass('grey-out');
}

image served from another site won't open popup

I think I know the answer already is probably "No", but I'll ask anyway, (as there may be a work around like a "lightbox" option etc)
I wrote a banner exchange script, with a difference. When the banner is clicked, a new window opens appears inviting the user to subscribe to a newsletter first, (or go straight to site)
This works fine if I use a window.open() prompt, as effectively the text for the popup is pulled in from URL of the window ... but I want to use a (modal?) window without the location bar etc. But here's the problem: The script runs on siteA, and displays the banners on HTML page of siteB. When you click the banner, it cannot access the javascript/CSS modal window code on the host HTML page. I think even with a light box div, the image or link has to be "hard coded" into the HTML page first. Can anyone envisage a work-around?
Here is what I've tried thus far (in simplified form):
<script>
hide id 0
</script>
<div>
<object data=pop-up text pulled from Site A: visibility:hidden id=0 width="720" height="600">
</div>
<object data=banner code pulled from SiteA width="490" height="90">
(I tried running the javascript from site A, and calling the hide routine via parent.document... to get to the javascript hide routine within the HTML page. Adding an alert to this 'calling' javascript, I get "SiteA says: hallo" when I click the banner)
I also tried jumping the banner to a script that would redraw the code to "_top" of the browser, and display the pop-up code in a div on this new page. I tried window.history.back to get the HTML from the page we've just left ... but all that does is reload the same page and discard the new code
I made the second object code above 'almost' same size as banner so text above and below if on HTML page flows properly.
On a slight tangent, it there a way to print a "block" of code in Javasript. In PERL, you can use "print <<EOF", but at present, if I want to print a large amount of text via javascript, I'm using +'xxxx xxx xxx xx' +'xxx xxx xxx' and escaping each and every single quote and newline. Is there a better way to print a line of code that contains numerous newline feeds?

How can I hide a div when my webpage is viewed in Lynx?

My website has a div element (in form of a block) that I want to make invisible whenever a user visits the website through a text based browser like Lynx, that doesn't support JavaScript.
Basically what command or code do I need to write in order for this to happen?
Since you can't run javascript there, you have to not send that div in the first place for it to be invisible in the text-mode browser.
You can make a server side user-agent check and do not render that div.
Lynx user agents:
http://www.useragentstring.com/pages/Lynx/
You can set the div invisible by default.
and make it visible in your js code.
Thus it'd not appear on a text-mode browser.

Categories