javascript - Error 'undefined' is null or not an object in Internet Explorer - Stack Overflow

In my magento code 1 file is there.Name of file - header.phtmlI got error like 'undefined' i

In my magento code 1 file is there. Name of file - header.phtml

I got error like 'undefined' is null or not an object.

And if i debug that page from IE itself than it will break code from "var hashIndex = frameId.indexOf('#');" from following code.

function getFrameId()
{
    var qs = parseQueryString(window.location.href);
    var frameId = qs["frameId"];

    var hashIndex = frameId.indexOf('#');

    if (hashIndex > -1)
    {
        frameId = frameId.substring(0, hashIndex);
    }

    return frameId;
}

In my magento code 1 file is there. Name of file - header.phtml

I got error like 'undefined' is null or not an object.

And if i debug that page from IE itself than it will break code from "var hashIndex = frameId.indexOf('#');" from following code.

function getFrameId()
{
    var qs = parseQueryString(window.location.href);
    var frameId = qs["frameId"];

    var hashIndex = frameId.indexOf('#');

    if (hashIndex > -1)
    {
        frameId = frameId.substring(0, hashIndex);
    }

    return frameId;
}
Share Improve this question asked Apr 26, 2012 at 6:08 dayanadayana 791 silver badge11 bronze badges 3
  • In the said line, try to see the value of frameId, I am afraid it is null. – Rakesh Juyal Commented Apr 26, 2012 at 6:12
  • Seems frameId is not beeing assigned a string but instead is undefined (probably). What is the value of qs? What should it be? What does parseQueryString do and what should it return? – RobG Commented Apr 26, 2012 at 6:21
  • alert(qs); -> return [object object] alert(frameId); -> return undefined and after that error box is open. alert(hashIndex); not execute at all. – dayana Commented Apr 26, 2012 at 6:45
Add a ment  | 

3 Answers 3

Reset to default 3

indexOf is not supported in IE. You will need to write your own indexOf function. For example:

//Implement indexOf. (IE/mshta doesn't have it)
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (obj, fromIndex) {
    if (fromIndex == null) {
        fromIndex = 0;
    } else if (fromIndex < 0) {
        fromIndex = Math.max(0, this.length + fromIndex);
    }
    for (var i = fromIndex, j = this.length; i < j; i++) {
        if (this[i] === obj)
            return i;
    }
    return -1;
  }; 

'undefined' is null or not an object means that the java script object that you invoked any method on , is either null or a value that doesn't support that particular method.

in this casevar frameId = qs["frameId"]; i think this returned null, could you see what the qs contains and if there are any value associated with frameid key

Try

 console.debug(qs); 

in firefox or chrome and inspect that object. Not only will you confirm that you have or haven't the frameId property in the object, but you'll also be able to inspect all the content of that object, and maybe find the information you're looking for in a different object key.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742337767a4424996.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信