浏览器关闭前提示

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

 

 

 

onbeforeunload information

 

 

 

Syntax

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

Event Information

BubblesNo
CancelsYes
To invoke
  • 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.
Default actionSignals 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

altKeySets or retrieves a value that indicates the state of the ALT key.
altLeftSets or retrieves a value that indicates the state of the left ALT key.
clientXSets 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.
clientYSets 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.
ctrlKeySets or retrieves the state of the CTRL key.
ctrlLeftSets or retrieves the state of the left CTRL key.
returnValueSets or retrieves the return value from the event.
shiftKeySets or retrieves the state of the SHIFT key.
shiftLeftRetrieves the state of the left SHIFT key.
typeSets 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 οnbefοreunlοad="closeIt()">
<a href="http://www.microsoft.com">Click here to navigate to
www.microsoft.com</a>
</BODY>
</HTML>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值