Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
匹配并替换完整的javascript函数_Javascript_Jquery_Function - Fatal编程技术网

匹配并替换完整的javascript函数

匹配并替换完整的javascript函数,javascript,jquery,function,Javascript,Jquery,Function,如何匹配当前页面上的整个JavaScript函数?我的JavaScript函数是: window.onbeforeunload = function() { if( !success ) { success = true; alert('Think first! Click CANCEL on the next page to receive a new gift.\n\n'); window.location = 'http://

如何匹配当前页面上的整个JavaScript函数?我的JavaScript函数是:

window.onbeforeunload = function()
{
    if( !success )
    {
        success = true;
        alert('Think first! Click CANCEL on the next page to receive a new gift.\n\n');
        window.location = 'http://www.mysite.com/';
        return '\nClick CANCEL\n\nOver thousands of gifts have been given out, get yours today!\n\n';
    }
}
我希望动态匹配并替换此函数以:

window.onbeforeunload=function()
{
    return ExitPopup();
}
请帮我解决这个问题。

你不能吗

var newFunction = function()
{
    return ExitPopup();
}
然后

window.onbeforeunload = newFunction;

为什么不像在第二个代码段中那样分配(覆盖)它呢?请不要在试图关闭页面时使用这种恼人的警报…为什么不编辑页面而不是动态地执行所有操作?第一个函数已经在我使用curl获得的页面上,我想用我的函数更改此函数