Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

javascript - How Can a parent window know that its child window closed?

I want to execute a function when an opened child window is closed. Child window opening code is:

outWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=600, height=400, top=100, left=100);

I want to call a Javascript function written in parent window. I am using YUI-2 for developing the plugin. How can I make it work? What event should be registered?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could do something like this.

var intervalID, childWindow;

childWindow = window.open("http://www.google.com");

function checkWindow() {
    if (childWindow && childWindow.closed) {
        window.clearInterval(intervalID);
        alert('closed');
    }
}
var intervalID = window.setInterval(checkWindow, 500);

References: window.setInterval and this answer.

Simple example on jsfiddle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...