久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是否可以以編程方式觸發 onbeforeunload 事件?

Is it possible to trigger the onbeforeunload event programmatically?(是否可以以編程方式觸發 onbeforeunload 事件?)
本文介紹了是否可以以編程方式觸發 onbeforeunload 事件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前正在使用 jquery-form-observe 插件使用 onbeforeunload 提示用戶有關未保存"的更改.

I'm currently using the jquery-form-observe plugin which uses onbeforeunload to prompt the user about "unsaved" changes.

但是我有一個場景,我需要在單擊按鈕時觸發它:按鈕單擊最終會導致頁面更改,但我想在用戶開始按鈕單擊開始的過程之前提示他們...

But I have a scenario where I need to trigger this on a button click: the button click ultimately leads to the page changing, but I want to prompt the user before they start the process that the button click kicks off...

那么有沒有辦法通過jQuery或其他方式觸發onb??eforeunload?

So is there a way to trigger onbeforeunload through jQuery or otherwise?

推薦答案

我不知道是否有直接的方法可以做到這一點,但你總是可以自己模擬瀏覽器的確認框.這是我根據 規范在MSDN:

I don't know if there is a direct way to do this, but you could always emulate the browser's confirmation box yourself. Here's a simple function I cooked up based on the specs at MSDN:

function triggerBeforeUnload() {
  var event = {};
  handler(event);

  if (typeof event.returnValue == 'undefined' ||
      confirm('Are you sure you want to navigate away from this page?

' + event.returnValue + '

Press OK to continue, or Cancel to stay on the current page.')) {
    // Continue with page unload
  } else {
    // Cancel page unload
  }
}

jquery.formobserver.js中,在function beforeunload(e) { ... }的定義之后,添加這一行:

In jquery.formobserver.js, right after the definition of function beforeunload(e) { ... }, add this line:

handler = beforeunload;

注意原代碼的變化:window.onbeforeunload已經被handler代替了.

Note the change in the original code: window.onbeforeunload has been replaced by handler.

這篇關于是否可以以編程方式觸發 onbeforeunload 事件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: av播播| 伊人精品在线 | 一级黄色av | av片在线免费观看 | 一级欧美一级日韩 | 黄色免费小视频 | 日本少妇久久 | 天天操天天操天天操 | 色综合天天综合网天天狠天天 | 日韩免费精品视频 | 九九热九九| 国产日韩精品一区二区 | 国产91精品在线观看 | 三级黄色网 | 欧美黄色一级 | 久久久一区二区 | 91丨九色丨国产在线 | 在线观看a视频 | 国产一区二区三区精品视频 | 免费午夜视频 | av女优天堂 | 国产wwwwww | 国产高潮在线观看 | 天堂网中文在线 | 在线观看日韩欧美 | 美女综合网 | 欧美日韩中文字幕 | 黄色三级免费 | 亚洲午夜在线 | 一区二区三区四区国产 | 日产精品久久久一区二区 | 日韩第一区 | 免费观看全黄做爰视频 | 国产免费av在线 | 依人在线| 黄色在线观看免费 | a级片在线观看 | 麻豆一区二区 | 热久久中文字幕 | 免费av在线| 亚洲一区网站 |