2

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のクエリ文字列に応じて変化するためです。

4

3 に答える 3

7

セキュリティ上の理由からできません。same-origin-policy (そして google.com は確かにあなたのドメインではありません) により、他のウィンドウの DOM へのアクセスは許可されません。

ポップアップが同じドメインからのものである場合、戻り値はwindow.openポップアップのwindowオブジェクトへの参照になります: https://developer.mozilla.org/en/DOM/window.open

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
}
于 2012-04-10T06:47:10.703 に答える
1

次のコードを使用してください。

a href="www.google.com" onclick="window.open(this.href, null, 'height=580, width=680, toolbar=0, location=0, status=1, scrollbars=1, resizable= 1'); false を返す"

于 2012-04-10T06:49:37.063 に答える
1

ベルギが言ったように、外部ドメインからDOMへの追加はありません。ただし、同じドメインの場合(ここから取得)

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

ここでも例を見ることができます。

于 2012-04-10T07:08:19.703 に答える