最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论