最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

jquery - Waiting for another page to load in JavaScript - Stack Overflow

matteradmin7PV0评论

is there a possibility to open a new window with JavaScript and wait with jQuery until the new page has finished loading?

I tried the following, but it did not work:

var win = window.open(url,'',windowSpec);
$(win.window).load(
    function () {
        alert('Finished loading');
    }
);

is there a possibility to open a new window with JavaScript and wait with jQuery until the new page has finished loading?

I tried the following, but it did not work:

var win = window.open(url,'',windowSpec);
$(win.window).load(
    function () {
        alert('Finished loading');
    }
);
Share Improve this question edited Dec 19, 2014 at 17:25 APerson 8,4308 gold badges38 silver badges49 bronze badges asked Sep 20, 2012 at 11:53 JanusJanus 3091 gold badge5 silver badges18 bronze badges 4
  • 3 is the url in the new window on the same domain as the calling script? – Gabriele Petrioli Commented Sep 20, 2012 at 11:57
  • Yes, it's all on the same server. – Janus Commented Sep 20, 2012 at 12:05
  • Can you edit the page loading in the popup? so to insert some javascript in it? – Nelson Benítez León Commented Sep 20, 2012 at 12:09
  • I tried it in the meantime and tried to access the second window with the following $(win.window).load and for the finishing of the loading. But it does not work. – Janus Commented Sep 20, 2012 at 12:12
Add a ment  | 

1 Answer 1

Reset to default 5

Since the opened url is on the same server, it means that the two windows can municate.

Add on the page that opens in the window

$(window).load(function() {
    var opener = window.opener || window.dialogArguments;
    if (opener) {
           opener.yourmethod();
       }
});

and on the page that initiates the window.open mand use

function yourmethod(){
  alert('Finished loading');
}

Demo at http://jsfiddle/nmXdc/1
(the window that opens from the click is at http://jsfiddle/FPcMk/1/)

Post a comment

comment list (0)

  1. No comments so far