Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-02-25
4
Medium Priority
?
1,016 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 45

Accepted Solution

by:
AndyAinscow earned 1500 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 45

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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