How can I notify the parent page when the popup has completed the download initiated by the parent?

My main HTML page does the following:

var popup = window.open(...);
// Wait for popup to load
popup.onload = function() { do_something(); };
popup.location = "new-page.html";

I would like it to be do_somethingcalled when new-page.htmlthe download is complete. But what I have now does not work - it is do_somethingnever called.

How can I do this job?

I only care that this works in FF 3.5 if this makes things easier.

+3
source share
5 answers

you can use window.opener. <functionName> and put your notification code inside this function on the parent page

+4
source

, HTML- , iframe. jQuery , .

HTML:

<iframe id="foo"></iframe>
<script type='text/javascript'>
    var element = $("#foo");
    element.load( function( eventObject ) { 
        // do something here
    } );
    // Now that the event listener is attached, we can set the source.
    element[0].src = "foo.html";

</script>

. , , , . , iframe / , . , src , , .

http://www.shanetomlinson.com

http://www.ubernote.com

+1

Try using the doSomething method, which is called in a popup. You can return to the parent using window.opener

0
source

In your downloaded .html you can have a simple one liner at the end that calls the function in the window that opens (if it exists)

<script type='text/javascript'>
if (window.opener && window.opener.do_something) window.opener.do_something(window);
</script>
0
source

Source: https://habr.com/ru/post/1715008/


All Articles