window.open的文档对象

时间:2011-11-25 16:30:03

标签: javascript

var theNewWindow = window.open('http://www.example.com', 'example', '');

如何使用document的{​​{1}}对象动态更新新窗口的dom。

2 个答案:

答案 0 :(得分:2)

如果您有权修改新窗口(例如same origin),那么您可以通过以下方式获取文档:

theNewWindow.document

答案 1 :(得分:2)

只有当新网页是同一个域或关于:空白时,您才可以。例如:

var temp = window.open('about:blank', 'example', '');
var div = temp.document.createElement("div");
div.innerHTML = "Hello!";
temp.document.body.appendChild( div );

see the working example

相关问题