读书人

浏览器封锁前提示

发布时间: 2012-11-21 08:23:26 作者: rapoo

浏览器关闭前提示

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

?

?

?

onbeforeunload information

?

?

?

EVENT = onbeforeunload> Internet Explorer only

Event Information

BubblesNoCancelsYesTo invoke

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 onbeforeunload="closeIt()"><a href="http://www.microsoft.com">Click here to navigate towww.microsoft.com</a></BODY></HTML>

读书人网 >Web前端

热点推荐