如何在javascript中向弹出窗口添加div?

如何在javascript中向弹出窗口添加div?,javascript,Javascript,我使用javascript中的以下代码创建了一个弹出窗口 window.open("http://google.com", "myWindow", "status = 1, height = 300, width = 300, resizable = 0"); 我需要在弹出窗口中添加以下动态div <div><img src="/images/img1.jpg" /></div> 上面的div是动态的,因为图像src将根据url中的查询字符串而变

我使用javascript中的以下代码创建了一个弹出窗口

  window.open("http://google.com", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
我需要在弹出窗口中添加以下动态div

 <div><img src="/images/img1.jpg" /></div>


上面的div是动态的,因为图像src将根据url中的查询字符串而变化,出于安全原因,您不能这样做。由于同源策略(而且google.com肯定不是您的域),您将不被允许访问另一个窗口的DOM

如果弹出窗口来自同一个域,
window.open
的返回值将引用弹出窗口的
window
对象:

var popup=window.open(“/relative path.html”,…);
popup.onload=function(){//当然,您可以使用其他onload技术
jQuery(popup.document.body).append(“”;//或任何其他dom操作
}

只需使用以下代码:


a href=“www.google.com”onclick=“window.open”(this.href,null,'height=580,width=680,toolbar=0,location=0,status=1,scrollbars=1,resizeable=1');返回false“

,正如bergi所说,没有从外部域附加到DOM。但对于同一域(取自)

win=window.open('about:blank','instructions','width=300,height=200');
doc=win.document;
doc.open();
书面文件(“说明”);
doc.close();
//对弹出窗口中div的引用
//->doc.getElementById('说明')

您也可以看到一个示例。

我可以使用javascriptYes从我的站点添加/删除内容吗;我已经扩展了答案。我尝试了同样的方法解决我的问题,但没有成功。
doc.open()
doc.close()
做什么?看来我不需要用这些。
var popup = window.open("/relative path.html", ...);
popup.onload = function() { // of course you can use other onload-techniques
    jQuery(popup.document.body).append("<div />"); // or any other dom manipulation
}
win=window.open('about:blank','instructions','width=300,height=200');
doc=win.document;
doc.open();
doc.write('<div id="instructions">instructions</div>');
doc.close();
//reference to the div inside the popup
//->doc.getElementById('instructions')