简体   繁体   中英

window.open(window.parent) possible?

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

window.location应该给您当前的Windows位置,因此:

window.open(window.location);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM