父窗口中有一个按钮,它将打开弹出窗口。
如果用户关闭弹出窗口,则父窗口应获得窗口焦点。
如何在普通javascript中做到这一点?
function Popup(url, title, w, h) {
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
if (window.focus) {
newWindow.focus();
}
newWindow.onunload = function() {
if (window.opener && !window.opener.closed) {
window.opener.focus();
}
};
}