久久久久久久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 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 欧美日韩综合精品 | 亚洲精品国产一区 | 羞视频在线观看 | 亚洲精品久久久久久久久久久久久 | 欧美一区二区三区电影 | 久久精品国产99国产精品 | 99久久久无码国产精品 | www4虎 | 91福利在线观看视频 | 亚洲精品永久免费 | 久久九精品 | 久久com| 免费亚洲视频 | 久久成人免费视频 | 国产精品久久久久久久久久三级 | 亚洲精品欧美精品 | 成人欧美一区二区三区 | 羞羞色网站 | 国产精品激情在线 | 一级做a爰片性色毛片 | 精品日韩在线 | 成人精品一区二区三区中文字幕 | 蜜臀久久 | 精品免费国产一区二区三区四区介绍 | 欧美成人h版在线观看 | 黄色网址免费在线观看 | 一区精品国产欧美在线 | 国产免费视频 | 亚洲精品国产区 | 中文无码日韩欧 | 一本一道久久a久久精品综合蜜臀 | 国产综合在线视频 | 羞羞视频在线观看 | 日本成人三级电影 | 国产高清免费视频 | 国产农村妇女精品一二区 | 国产成人网 | 欧美福利视频 | 久久久精品一区二区三区 | 激情黄色在线观看 | 国产香蕉视频在线播放 |