简体   繁体   中英

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

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???

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;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM