匹配并替换完整的javascript函数

时间:2011-12-15 17:48:08

标签: 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://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();
}

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

你能不能做到

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

然后

window.onbeforeunload = newFunction;