久久久久久久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 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 伊人春色成人网 | 欧美一级黄色网 | 999在线精品| 特黄色一级毛片 | 久久新 | 九九免费视频 | 亚洲一区二区三区观看 | 欧美精品一区二区三区四区五区 | 成人黄色三级毛片 | 欧美在线观看免费观看视频 | 人人九九精 | 中文字幕av色 | 欧美韩一区二区三区 | 亚洲精品一 | 欧美中文一区 | m豆传媒在线链接观看 | 999热视频| 在线欧美| 国产高清久久 | 三级黄色网址 | 狠狠色综合欧美激情 | 91精品国产色综合久久不卡蜜臀 | 久久久久久国产精品免费 | 欧美极品在线播放 | 成人欧美一区二区三区在线观看 | 久久一区二区视频 | 少妇无套高潮一二三区 | 国产精品爱久久久久久久 | 亚洲视频在线播放 | 日韩高清在线观看 | 99亚洲精品 | 精品一区二区av | 国产高清久久久 | 精品久久久久久久久久久久久 | 81精品国产乱码久久久久久 | 亚洲成人久久久 | 韩国精品一区二区三区 | 97国产精品视频人人做人人爱 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 福利视频一区 | 午夜成人免费视频 |