Solved

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

Posted on 2014-02-25
4
959 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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