如何使用Greasemonkey阻止在jquery中删除或停止匿名函数

时间:2013-09-30 19:25:42

标签: javascript jquery greasemonkey

如何阻止以下jquery函数。 我测试了不同的脚本和自己的脚本,但注意到了工作。

$(document).ready(function () {

  $(window).on('beforeunload', function() {
        return "\
Are you sure you want to leave this page....";
  });
});

很抱歉,但这两个脚本都没有停止离开对话框

// ==UserScript==
// @name           Test
// @namespace      
// @description    Disable - remove the annoying onbeforeunload event
// @include        *
// @author         test
// ==/UserScript==

(function() {
      unsafeWindow.onbeforeunload = null;

      unsafeWindow.onunload = null;

      //unsafeWindow.alert = null;

      //unsafeWindow.confirm = null;

      //unsafeWindow.prompt = null;

      //unsafeWindow.open = null;

      //$(window).off('beforeunload'); //don't work
$(window).on('beforeunload',function() {/* override function that does nothing*/});
})();

1 个答案:

答案 0 :(得分:4)

我相信off正是您所寻找的:

$(window).off('beforeunload');