简体   繁体   English

使用javascript禁用IE中的关闭按钮

[英]Disable close Button in IE with javascript

Can I disable close button in IE using javascript? 我可以使用javascript禁用IE中的关闭按钮吗? maybe like "Resizeable =no ". 也许像“可调整大小=否”。 But i dont want to use "fullscreen = yes". 但我不想使用“全屏=是”。 How ? 怎么样 ?

Thx 谢谢

This is impossible in modern browsers. 在现代浏览器中这是不可能的。 Browser makers want to provide a user-friendly and relatively predictable experience, which includes not making features that would be useful primarily to makers of spyware or heavily obnoxious, impossible-to-close-without-clicking ads. 浏览器制造商希望提供用户友好且相对可预测的体验,其中包括不提供主要对间谍软件制造商或极为讨厌,无法关闭而无需点击的广告有用的功能。

The best you can do is to capture the user leaving the page and popup a dialog asking them if they're sure they want to. 最好的办法是捕获离开页面的用户,并弹出一个对话框,询问他们是否确定要这样做。 You cannot cancel the event. 您无法取消活动。

Example (works in IE): 示例(适用于IE):

window.onbeforeunload = function(evt)
        {
            if (unsavedData)
            {
                var message = 'Leaving the page will result in the loss of unsaved data.';
                if (typeof evt == 'undefined')
                {
                    evt = window.event;
                }
                if (evt)
                {
                    evt.returnValue = message;
                }
                return message;
            }

        }

出于安全原因,您不能仅使用javascript来做到这一点。

If this is for an intranet site or a kiosk, you can use HTML Applications. 如果这是针对Intranet网站或自助服务终端的,则可以使用HTML应用程序。 HTML Applications are just HTML files that can be made to look and feel like regular Windows applications. HTML应用程序只是可以使它们看起来和感觉像普通Windows应用程序的HTML文件。

If, for example, you want a full screen Kiosk application just install a proper HTA file on the computer at runs on start up with the following configuration in the head section: 例如,如果您要使用全屏Kiosk应用程序,则只需在启动时运行时在头部分中进行以下配置,即可在计算机上安装正确的HTA文件:

<HTA:APPLICATION ID="MyApp" 
    APPLICATIONNAME="Kiosk" 
    BORDER="none"
    CAPTION="no"
    ICON="/graphics/creature.ico"
    SHOWINTASKBAR="no"
    SINGLEINSTANCE="yes"
    SYSMENU="no"
    WINDOWSTATE="maximize">

The Border="none" part makes a window that doesn't have a close button. Border =“ none”部分使窗口没有关闭按钮。

Remember though, this wont work on a regular web page because disabling the close button is a dangerous thing for an untrusted web page to do. 但是请记住,这在常规网页上不起作用,因为禁用关闭按钮对于不可信的网页来说是一件危险的事情。 By using an HTA you tell Windows that you can trust this page. 通过使用HTA,您告诉Windows您可以信任此页面。

The HTA reference is here: http://msdn.microsoft.com/en-us/library/ms536473%28VS.85%29.aspx HTA参考位于此处: http : //msdn.microsoft.com/zh-cn/library/ms536473%28VS.85%29.aspx

And a tutorial: http://msdn.microsoft.com/en-us/library/ms536496%28VS.85%29.aspx 还有一个教程: http : //msdn.microsoft.com/en-us/library/ms536496%28VS.85%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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