Solved

Error: Unable to get property 'lastIndexOf' of undefined or null reference

Posted on 2014-02-25
4
915 Views
Last Modified: 2014-02-25
Hi,
i'm getting this error on IE10 browser for but this is happening only in one instant..
MasterScriptIns = MasterScriptIns.nextSibling;
    var InnerScript = MasterScriptIns.innerHTML;
    var Index = InnerScript.lastIndexOf("WebForm_AutoFocus('");
    if(Index == -1)
    {
        window.focus();
        return false;
    }


please advice
0
Comment
Question by:Saikat M
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39885470
Does this work?  

var InnerScript = MasterScriptIns.innerHTML;
if(InnerScript != null)
{
    var Index = InnerScript.lastIndexOf("WebForm_AutoFocus('");
    if(Index == -1)
    {
        window.focus();
        return false;
    }
}
0
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 39885482
Hi

This means that MasterScriptIns.innerHTML returns something different than string.

You have to make a check after each assignment to see what have you gotten.

you could restate this as follow:
MasterScriptIns = MasterScriptIns.nextSibling; // you have to check after this assignment.
var InnerScript = MasterScriptIns.innerHTML || ""; // in the case InnerScript will be empty string and won;t fire the error

Open in new window


HTH

Ivo Stoykov
0
 

Author Comment

by:Saikat M
ID: 39885502
Thanks a ton. It worked out.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39885545
A rapid response, A correct answer (with code) that works. Then why only a 'B' grade?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question