`

浏览器关闭前提示

阅读更多

<script> window.onbeforeunload=function(){ return "尊敬的Software②China成员,您还未向朋友们打招呼"; } </script>

 

 

 

onbeforeunload information

 

 

 

Syntax

Inline HTML Event property Named script
<ELEMENT onbeforeunload = "handler" ... > All platforms
object.onbeforeunload = handler JScript only
object.onbeforeunload = GetRef("handler") Visual Basic Scripting Edition (VBScript) 5.0 or later only
<SCRIPT FOR = object EVENT = onbeforeunload> Internet Explorer only

Event Information

Bubbles Cancels To invoke Default action
No
Yes
  • Close the current browser window.
  • Navigate to another location by entering a new address or selecting a Favorite.
  • Click the Back, Forward, Refresh, or Home button.
  • Click on an a that refers the browser to another Web page.
  • Invoke the a?A HREF="../methods/click.html">click method.
  • Invoke the document?A HREF="../methods/write.html">write method.
  • Invoke the document?A HREF="../methods/open_1.html">open method.
  • Invoke the document?A HREF="../methods/close_1.html">close method.
  • Invoke the window?A HREF="../methods/close_0.html">close method.
  • Invoke the window?A HREF="../methods/open_0.html">open method, providing the possible value _self for the window name.
  • Invoke the window?A HREF="../methods/navigate.html">navigate or NavigateAndFind method.
  • Invoke the location?A HREF="../methods/replace.html">replace method.
  • Invoke the location?A HREF="../methods/reload.html">reload method.
  • Specify a new value for the location?A HREF="../properties/href_3.html">href property.
  • Submit a form to the address specified in the action attribute via the input type=submit control, or invoke the form?A HREF="../methods/submit.html">submit method.
Signals that the page is about to be unloaded.

Event Object Properties

Although event handlers in the DHTML Object Model do not receive parameters directly, a handler can query an event object for data.

Show Available Properties

altKeyaltLeftclientXclientYctrlKeyctrlLeftreturnValueshiftKeyshiftLefttype
Sets or retrieves a value that indicates the state of the ALT key.
Sets or retrieves a value that indicates the state of the left ALT key.
Sets or retrieves the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
Sets or retrieves the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
Sets or retrieves the state of the CTRL key.
Sets or retrieves the state of the left CTRL key.
Sets or retrieves the return value from the event.
Sets or retrieves the state of the SHIFT key.
Retrieves the state of the left SHIFT key.
Sets or retrieves the event name from the event object.

Remarks

When a string is assigned to the returnValue property of window.event, a dialog box appears that gives users the option to stay on the current page and retain the string that was assigned to it. The default statement that appears in the dialog box, "Are you sure you want to navigate away from this page? ... Press OK to continue, or Cancel to stay on the current page.", cannot be removed or altered.

Example

This example uses the onbeforeunload event to ask users whether they want to remain on the current page or navigate to a new URL. When the user clicks on the hyperlink or attempts to close the browser window, the onbeforeunload event fires on the body and a dialog box appears. If the user chooses 'OK', the page navigates to the new URL (www.microsoft.com) or closes the window; if the user chooses 'Cancel', the page remains the same.

SHOWExample

<HTML>
<HEAD>
<SCRIPT>
function closeIt()
{
event.returnValue = "Any string value here forces a dialog box to \
appear before closing the window.";
}
</SCRIPT>
</HEAD>
<BODY onbeforeunload="closeIt()">
<a href="http://www.microsoft.com">Click here to navigate to
www.microsoft.com</a>
</BODY>
</HTML>
分享到:
评论

相关推荐

    JS针对浏览器窗口关闭事件的监听方法集锦

    下面将详细介绍几种常用的浏览器关闭事件监听方法。 1. 方式一:适用于IE浏览器,仅在关闭时提示 ```javascript window.onbeforeunload = onclose; function onclose() { if (event.clientX &gt; document.body....

    js关闭浏览器窗口及检查浏览器关闭事件

    js关闭浏览器窗口 js关闭浏览器窗口,不弹出提示框。支持ie6+,火狐,谷歌等浏览器。 代码如下: &lt;html&gt; &lt;head /&gt; &lt;body&gt; [removed] function closeWin(){ window.opener=null; window.open(”,’_...

    JS监听关闭浏览器事件

    在Web开发中,有时我们需要对用户关闭浏览器窗口或标签页的行为进行监测,并在这些行为发生前执行某些操作。这通常涉及到`onbeforeunload`和`onunload`这两个事件处理程序。 #### 1. `onbeforeunload`事件 `...

    判断浏览器是刷新还是关闭窗口

    ### 判断浏览器是刷新还是关闭窗口 在网页开发过程中,我们常常希望能在用户退出或离开当前页面时执行一些特定的操作,比如保存用户的状态、显示一个警告框等。为此,JavaScript 提供了 `onunload` 事件,它会在...

    JS网页定时自动关闭-无浏览器提示

    本示例将详细介绍如何在不触发浏览器确认提示的情况下实现网页的自动关闭。 首先,我们需要了解JavaScript中的定时器函数`setTimeout()`。这个函数可以安排一个函数或一段代码在指定的毫秒数后执行。例如,如果我们...

    js实现用户离开页面前提示是否离开此页面的方法(包括浏览器按钮事件)

    本文实例讲述了js实现用户离开页面前提示是否离开此页面的方法(包括浏览器按钮事件)。分享给大家供大家参考。具体如下: 用户离开页面前,提示是否离开此页面(包括浏览器按钮事件) [removed] [removed] = ...

    vue如何在用户要关闭当前网页时弹出提示的实现

    本文介绍了vue如何在用户要关闭当前网页时弹出提示的实现,分享给大家,具体如下: 效果如下图 正常 js 页面处理方式 [removed] = function (e) { e = e || window.event; // 兼容IE8和Firefox 4之前的版本 if ...

    JS区分浏览器页面是刷新还是关闭

    产品经理可能会提出更细致的需求,例如在页面关闭时和页面刷新时提供不同的提示信息,或者在页面刷新时需要有延时操作,比如在客服系统中,为了避免电话系统频繁签入签出导致的问题,可能会设置一个延时再让用户重新...

    微信浏览器内显示遮罩层提示点击右上角

    本文将详细探讨如何实现“微信浏览器内显示遮罩层提示点击右上角,选择在浏览器中打开链接”的功能,以及相关技术要点。 首先,我们需要理解微信内置浏览器(X5内核)的工作原理。微信浏览器是基于腾讯自家的X5 ...

    微信QQ内置浏览器打开网址跳转提示页面美化版.zip

    搞一个遮罩(跳转浏览器提示)就OK了 迷惑性问题: 问:这个干什么用的。答:微信QQ打开网站提示 问:怎么用 答:放在网站运行目录 使用教程: 1.上传插件整个文件夹到网站根目录。得到: /WxqqJump 2.修改 /index...

    防红专用 QQ微信打开提示跳转浏览器的代码

    3、复制前请先修改本站名字、链接 替换成 自己的网站名字、链接。 批量替换(可用notepad++等软件进行批量修改): 使用说明: 手机QQ内打开会自动跳转浏览器; 手机微信内打开需用用户手动跳转; 用户可选择...

    onunload事件判断浏览器是刷新还是关闭窗口

    这个方法的原理是,当浏览器关闭时,window.event.screenX 和 window.event.clientY 属性的值将满足一定的条件,因此可以根据这个条件来判断浏览器是刷新还是关闭窗口。 我们可以使用 onunload 事件和 event....

    关闭浏览器时提示onbeforeunload事件

    在最新版本的浏览器中,出于安全和用户体验的考虑,浏览器可能会限制`onbeforeunload`事件的使用,比如不再允许自定义对话框的文本,而是显示默认的提示信息。 `onbeforeunload`事件的常见应用场景包括: 1. **...

    js 无提示关闭浏览器页面的代码

    接下来,将详细探讨无提示关闭浏览器页面的方法及相关知识点。 首先,需要明确的是,出于安全原因,关闭浏览器标签页或窗口可能在某些情况下受限。例如,用户可能设置了浏览器安全设置阻止脚本关闭窗口,或者某些...

    浏览器常见故障解决方法

    可以在浏览器设置中关闭此功能。 3. **更新显卡驱动**:显卡驱动程序的过时也可能导致浏览器崩溃。访问显卡制造商的官方网站下载最新的驱动程序进行更新。 4. **使用安全模式**:某些浏览器提供安全模式,可以帮助...

    C#浏览器,真正屏蔽所有弹窗。我见过最好的

    此外,还可以设置控件的`ScriptErrorsSuppressed`属性为`true`来抑制脚本错误提示,进一步增强用户体验。 在【www.0554ak.com】和【www.5184go.com】这两个网站中,可能提供了关于这款C#浏览器的更多信息,如下载、...

    js无提示关闭浏览器窗口的两种方法分析

    在JavaScript中,无提示关闭浏览器窗口的操作可能会受到浏览器安全策略的限制,主要是为了防止恶意脚本强制关闭用户未预期的窗口。以下将详细介绍两种在不同情况下尝试关闭浏览器窗口的方法: 1. 使用JavaScript的`...

    MFC浏览器的定制与扩展

    ### MFC浏览器的定制与扩展 #### 前言 在软件开发过程中,尤其是在桌面应用程序领域,有时我们需要在自己的程序中嵌入一个浏览器组件来显示网页或其他HTML内容。Microsoft Foundation Classes (MFC) 提供了一套强大...

    两款网页右下角消息提示框 兼容多个浏览器

    5. **关闭按钮**:用户应能轻松关闭提示框,避免信息过载或打扰用户的工作流程。 6. **兼容性**:确保在各种浏览器中都能正常显示和功能完整,这通常需要使用跨浏览器的CSS和JavaScript技术,如使用Bootstrap、...

Global site tag (gtag.js) - Google Analytics