Dragunov
04-19-2005, 06:49 AM
Right, i've got a website up which contains an iframe (id is main) in which all the pages are loaded. On my parent page, I have an image. What code can I use such that when I click on that image, whatever page is currently in the iframe is opened in a new window.
Thanks in advance. :)
glenngv
04-19-2005, 07:15 AM
function doOpen(){
var w = window.open(document.getElementById("main").src, "mypopup");
w.focus();
return false;
}
...
<a href="#" onclick="return doOpen()"><img src="open.gif" /></a>
If document.getElementById("main").src doesn't work, try replacing it with:
document.getElementById("main").contenWindow.location.href
Dragunov
04-19-2005, 07:32 AM
Hmmmm...
The code manages to open a new window, but it only opens the default page of the iframe regardless of what page is currently loaded into it.
glenngv
04-19-2005, 07:40 AM
Did you try the second suggestion that uses contentWindow?
Dragunov
04-19-2005, 07:56 AM
Yeah, the second one gives me an error:
'document.getElementById(...).contenWindow.location' is null or not an object
snowieken
04-19-2005, 08:23 AM
Yeah, the second one gives me an error:
'document.getElementById(...).contenWindow.location' is null or not an objectThat's because it is contentWindow :)
(glenn made a typo)
The src property returns the src given by default in the code, that is why it always returns the default page, by the way. ContentWindow should work.
Dragunov
04-19-2005, 08:26 AM
Ack, how silly of me. I should have noticed that. :D
Thanks, both of you. :)
btw, is there anyway I can make the new window pop up maximised?
glenngv
04-19-2005, 08:33 AM
That's because it is contentWindow :)
(glenn made a typo)
Oopps...Sorry about that. :p
Here's the code to maximize the popup window:
function doOpen(){
var w = window.open(document.getElementById("main").contentWindow.location.href, "mypopup", 'resizable=1, left=0, top=0, width='+screen.availWidth+', height='+screen.availHeight);
w.focus();
return false;
}
Dragunov
04-19-2005, 08:53 AM
It all works. Thank you. :)