13

開いている子ウィンドウのドキュメントが読み込まれ、準備ができたときに通知を受け取ろうとしています。これは機能していないようです:

win = window.open(href, 'test', 'width=300, height=400');
win.focus();
$(win.document).ready(function() {
           // Ok, the function will reach here but if I try to manipulate the
           // DOM it doesn't work unless I use breakpoints
           $(this).contents().find("...").doStuff(); // nothing happens
    });

私は何をしなければなりませんか?

4

4 に答える 4

10

これを試しましたか?—</p>

$(win.document).ready(function() {
    $(win.document).contents().find("...").doStuff();
});

この質問は、非常によく似たものについて説明しています。複製?

于 2011-01-30T11:29:24.260 に答える
6

同様の問題があり、ウィンドウの .load イベントは機能しましたが、.ready は機能しませんでした。だからあなたは試すことができます:

win = window.open(href, 'test', 'width=300, height=400');
$(win).load(function() {
    $(this).contents().find("...").doStuff(); 
});
于 2013-02-19T16:03:16.947 に答える
1

window.opener読み込んでいるサイトのスクリプトで使用し、最初のページでグローバル (!) で定義された関数を実行します。

メインページ:

<html>
<head>
<script type="text/javascript">
    window.notify = function () {
        alert('runned from opened window');
    };
    window.onload = function() {
        document.getElementById('button').addEventListener('click', function() {
            window.open('test.html');
        }, false);
    };
</script>
</head>
<body>
<button id="button">Open window</button>
</body>

開いたページ:

<html>
<head>
<script type="text/javascript">
    window.onload = function() {
        window.opener.notify()
    };
</script>
</head>
<body>
    Popup site
</body>
</html>
于 2011-01-30T11:53:37.090 に答える