简体   繁体   中英

how to detect if child window has been submitted using javascript?

i have a child window whereby it contains the twitter sharing page... how to detect if the twitter sharing form has been submitted to twitter? note: this is a child window..

because I want to show an alert box after the sharing window closes twitter sharing submit detection

var myWindow;
    function openTwitterWindow(url){
    var width=550;var height=425;var left=parseInt((screen.availWidth/2)-(width/2));
    var top=parseInt((screen.availHeight/2)-(height/2));
    var windowFeatures="width="+width+",height="+height+",status,resizable,left="+left+",top="+top+"screenX="+left+",screenY="+top;
    myWindow=window.open(url,"subWind",windowFeatures);
    jQuery('form#update-form').submit(function(){
        onWindowClose(myWindow, myCallback);
    });
   }


    function myCallback() {
        alert("Your message has been shared. Thank you");
    }   

    function onWindowClose(windowRef,callback, period) {
        period = period || 20;
        setTimeout(function check() {
            if(windowRef == null || windowRef.closed) {
                callback();
            } else {
                setTimeout(check, period);
            }
        }, period);
    } 

THAT CODE ABOVE IS WRONG...I NEED HELP

<a style="cursor: pointer" onclick="openTwitterWindow('https://twitter.com/share?url=<?php echo $url; ?>&text= and so on and so forth...

You can try something like this:

var child = window.open('urlofchild');
var closetime = setInterval(checkChildClose, 500);

function checkChildClose() {
    if (child.closed) {
        alert("Child window closed");   
        clearInterval(closetime);
    }
}

Usually, when I design 'child' windows I use CSS and do virtual windows. Then you have all the information you need within a page. Then, you can use AJAX and JSON to work with the data.

Demo: http://www.codesoaked.com/demo/css-popup-window.html#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM