首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JS -检查网页是否关闭

JS -检查网页是否关闭
EN

Stack Overflow用户
提问于 2015-01-12 17:04:29
回答 2查看 1.2K关注 0票数 1

我试图在网页关闭的过程中触发一个事件。

方案是-一个网站打开一个单独的窗口,用户可以选择最小化。然后,这个最小化的页面等待用户关闭,或者在继续编写脚本之前完全离开主页导航。

我看过jQuery unload()方法,但我认为它不够具体,即它在任何类型的导航(刷新、菜单导航等)上都会触发。

是否可以使用此方法或另一种方法来实现此操作?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-12 18:41:59

这是不可能的,因为没有WINDOW_CLOSED事件,因为像浏览器主窗口一样显示的窗口对象属于底层操作系统的权限。即使在TDI(选项卡式文档接口) (如Microsoft的MDI在浏览器中实现)的情况下,在关闭选项卡时也不会触发任何事件。

票数 1
EN

Stack Overflow用户

发布于 2015-01-12 17:58:38

var winObj = null;var SixView =函数(a,b,c) { var popUpPageUrl = "../ViewDrawing.aspx?a=“+ $('id*=hdnAhuId').val() + "&compPosition=”+ spobtId + "§ionName=“+ c;winObj = myOpenWindow(popUpPageUrl,"myWin",winObj);}

代码语言:javascript
复制
function myOpenWindow(winURL, winName, winObj) {
    var theWin; // this will hold our opened window 

    // first check to see if the window already exists
    if (winObj != null) {
        // the window has already been created, but did the user close it?
        // if so, then reopen it. Otherwise make it the active window.
        if (!winObj.closed) {
            var result = confirm("Do you want to save the changes made in six view drawing ?");
            if (result) {
                saveChanges();
            }
            winObj = window.open(winURL, winName);
            winObj.focus();
            return winObj;
        }
        // otherwise fall through to the code below to re-open the window
    }

    // if we get here, then the window hasn't been created yet, or it
    // was closed by the user.
    theWin = window.open(winURL, winName);
    return theWin;
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27907153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档