Solved

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

Posted on 2014-02-25
4
858 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now