关闭弹出窗口
我找到了一个负责打开我需要的弹出窗口的代码:
function winOpen(theURL, Name, popW, popH, scroll) { // V 1.0
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp =
'width='+popW+',height='+popH+',left='+winleft+',t op='+winUp+',scrollbars='+scroll+','
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4){
Win.window.focus();
}
是否可以在此处包含在关闭窗口时提交的函数,或者是否需要在某处进行单独的函数调用?我在 html 链接上调用打开窗口。
I found a code that takes care of opening popup window I need:
function winOpen(theURL, Name, popW, popH, scroll) { // V 1.0
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp =
'width='+popW+',height='+popH+',left='+winleft+',t op='+winUp+',scrollbars='+scroll+','
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4){
Win.window.focus();
}
Is it possible to include here functions, that are commited when the window is closed, or does it require a separate function call somewhere? I'm calling window open on a html link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在弹出窗口中显示的页面可能有一个附加到
body
的onunload
或onbeforeunload
的事件处理程序(我认为这仅适用于 IE) )。如果文档卸载(谁会猜到这一点?),它将触发。如果文档内没有用于卸载该文档的链接,则可以将此事件视为窗口已关闭的指示符。第二种可能性:添加看门狗。
The page you are showing inside the popup could have an event handler attached to the
body
'sonunload
oronbeforeunload
(I think that is IE only). That will fire if the document unloads (who would have guessed that?). If you don't ave links inside the document that will unload it, you can take this event as an indicator that your window has been closed.Second possibility: add a watchdog.
您应该稍微缩进代码以使其更具可读性。另外,您可以使用
win.close
查看它是否已关闭onunload
,但请确保在检查之前稍等一下:http://jsfiddle.net/9PYWj/。You should indent your code a little to make it more readable. Also, you can use
win.closed
to see it's closedonunload
, but make sure to wait a little before checking: http://jsfiddle.net/9PYWj/.