开发者

How do I solve the JavaScript error: method XX is undefined?

开发者 https://www.devze.com 2023-01-12 17:36 出处:网络
I am working on asp.net and jquery website , and when run browse the site an java script error has occurred .

I am working on asp.net and jquery website , and when run browse the site an java script error has occurred . Visual studio debuger references that GetMainFrameUrl is undefined :

function EBNavigateComplete() 
{
    if (!GetMainFrameUrl())
    {
        navCounter++;
        if (navCounter%100==0)
        {
            o.loadEmptyTerm();
            counter = 0;
        }
    }
    else
    {
        if (o.pbNavigateComplete(GetMainFrameUrl()))
        {
       开发者_运维百科     counter = 0;
        }
    }
}

is there help please???


Are you using the Conduit API? If so, do you have that script library referenced? http://www.conduit.com/Developers/HtmlAndGadget/Methods/GetMainFrameUrl.aspx http://www.conduit.com/Developers/HtmlAndGadget/Events/EBNavigateComplete.aspx


Visual Studio debugger isn't always capable of loading all dynamically loaded scripts (but normally it does though). Is the same error occurring if you run it in, say, Firefox or Opera?

The error means that the function GetMainFrameUrl is not defined. That can happen if you misspelled the name of an existing function, or when the function is loaded only later in the chain. In the latter case, change the order of your <script> blocks to have the one with GetMainFrameUrl in it load first.

One easy way to find out whether that function is available somewhere is hitting Ctrl-Shift-F in Visual Studio, select "Entire Solution" and nothing for the file filter and search for the name of the missing function.


If you whant to check if the GetMainFrameUrl-function exists you cant use "if (!GetMainFrameUrl())". In this case javascript execute the function and comprare the return value. You can use "if (!GetMainFrameUrl)" but this only checks if any function, object or variable exists with this name. You should use "typeof". See exampel:

function EBNavigateComplete() 
{
    if ( typeof GetMainFrameUrl !== 'function' )
    {
        navCounter++;
        if (navCounter%100==0)
        {
            o.loadEmptyTerm();
            counter = 0;
        }
    }
    else
    {
        if (o.pbNavigateComplete(GetMainFrameUrl()))
        {
            counter = 0;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消