window.open(window.parent) possible?

window.open(window.parent) possible?

本文关键字:window possible parent open      更新时间:2023-09-26

我有一个按钮,当用户单击按钮时,此代码被触发...

window.open('','','width=640,height=480,resizeable,scrollbars');

这将打开一个新窗口。我想要显示的是该新窗口中的当前页面,所以我尝试了。.

window.open('window.parent.getElementById("printPage")','','width=640,height=480,resizeable,scrollbars');

但它所说的只是找不到该文件:(

谁能告诉我我做错了什么,如果这可能,我该如何解决?

谢谢J

window.location应该给你当前的窗口位置,所以:

window.open(window.location);

window.open()需要一个URI作为第一个参数。将其留空(在第一个示例中(似乎默认为 about:blank ,但第二个示例中的字符串 'window.parent.getElementById("printPage")' 实际上不是有效的 url。

如果需要当前窗口的 url,可以使用window.location

 window.open(window.location,'','width=640,height=480,resizeable,scrollbars');

您似乎试图从父帧中获取某些元素的 href 或 src 属性。您需要对其进行编码,不会评估一串代码。使用类似的东西

 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');

相反。