Can I open a new window and change the DOM of the calling window in JavaScript?

被刻印的时光 ゝ 提交于 2019-12-06 05:32:08

In response to your answer: you can modify the caller window's DOM by using window.opener.document from the new window;

window.opener is a reference to the caller window (if any, otherwise null), but only if both windows are from the same domain).

NOTE: Is it a small webpage or you are going to do a lot of DOM manipulation on a web site/application via javascript? In the later case you should use a javascript library/framework (I recommend jQuery) in order to do the dirty job more easily.

A popup window can find the window that opened it using the opener variable.

If both the popup window and the original window originate from the same domain, then the popup window can indeed modify the HTML of the original window.

If the popup window and the original window contain content from a different domain, then they can't see the HTML of each other - due to the cross-origin protection that browsers put in place.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!