window.open(window.parent) possible?
-
09-06-2021 - |
Question
I have a button and when the user clicks the button this code is triggered...
window.open('','','width=640,height=480,resizeable,scrollbars');
which opens a new window. What I want displayed is the the current page in that new window so I tried..
window.open('window.parent.getElementById("printPage")','','width=640,height=480,resizeable,scrollbars');
but all it says is that the file is not found :(
Can anyone tell me what I am doing wrong, if this is possible and how do i fix it?
Thanks, J
Solution
window.location
should give you the current windows location, so:
window.open(window.location);
OTHER TIPS
window.open()
needs a URI as the first parameter. Leaving it empty (in your first example) seems to default to about:blank
, but the string from your second example, 'window.parent.getElementById("printPage")'
, is really not a valid url.
If you want the url of the current window, window.location
can be used:
window.open(window.location,'','width=640,height=480,resizeable,scrollbars');
You seem to try to get some element's href or src attribute from the parent frame. You need to code that, a string of code won't be evaluated. Use something like
var url = window.parent.getElementById("printPage").src; // I'm guessing that
// "printpage" is a (i)frame
window.open(url, '','width=640,height=480,resizeable,scrollbars');
instead.