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

javascript - Member not found IE error (IE 6, 7, 8, 9) - Stack Overflow

programmeradmin6浏览0评论

Let me just first point out to any IE users right now (this is not a problem in Chrome, Safari or Firefox) hint hint ;)

So... I have a issue with my tooltips in IE, I have a onmouseover listener for all the elements which are to be hoverable and then in my mouseover function I have a very basic cross browser declaration as such...

var event = e || window.event,
    el = event.target || event.srcElement;

I've been having issues with the window object not existing in IE or something, this has been a issue after I added a flag to ignore mouseover's from one element mouseover on the way to the tooltip itself (during the time cycle allowed, 300ms). In other words the flag is to ignore mouseovers on route to the tooltip from the original mouseover.

So that logic looks like this...

loadtip.refMouseOver = function (e) {

    var event = e || window.event, el = event.target || event.srcElement;
    //console.log(window); // <-- throws error in IE (Member not found)
    // Reset the lastHoveredRef data.
    tipManager.lastHoveredRef = null;
    tipManager.lastHoveredRef = [el, event];

    // true means there is a tip open still, so if no tip is open.
    if (tipManager.tipState !== true) { 
        tipManager.processTip(el, event);
    } else {        
        return; // do nothing
    }

}

The "Member not found" error will occur when I hover from one element quickly to the next in IE with the tooltip still open.

I read about window.open and close stuff with a try catch but I didn't see how that was relevant. Any help is greatly appreciated.

Let me just first point out to any IE users right now (this is not a problem in Chrome, Safari or Firefox) hint hint ;)

So... I have a issue with my tooltips in IE, I have a onmouseover listener for all the elements which are to be hoverable and then in my mouseover function I have a very basic cross browser declaration as such...

var event = e || window.event,
    el = event.target || event.srcElement;

I've been having issues with the window object not existing in IE or something, this has been a issue after I added a flag to ignore mouseover's from one element mouseover on the way to the tooltip itself (during the time cycle allowed, 300ms). In other words the flag is to ignore mouseovers on route to the tooltip from the original mouseover.

So that logic looks like this...

loadtip.refMouseOver = function (e) {

    var event = e || window.event, el = event.target || event.srcElement;
    //console.log(window); // <-- throws error in IE (Member not found)
    // Reset the lastHoveredRef data.
    tipManager.lastHoveredRef = null;
    tipManager.lastHoveredRef = [el, event];

    // true means there is a tip open still, so if no tip is open.
    if (tipManager.tipState !== true) { 
        tipManager.processTip(el, event);
    } else {        
        return; // do nothing
    }

}

The "Member not found" error will occur when I hover from one element quickly to the next in IE with the tooltip still open.

I read about window.open and close stuff with a try catch but I didn't see how that was relevant. Any help is greatly appreciated.

Share Improve this question edited Apr 23, 2022 at 8:50 Brian Tompsett - 汤莱恩 5,87572 gold badges61 silver badges133 bronze badges asked Aug 20, 2010 at 14:21 yektayekta 3,4333 gold badges36 silver badges50 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 43

Ok I have found the problem.

To sum it up, basically IE will not pass a event to another function if that function call is within a setTimeout.

So you can trick IE by creating a copy of the event and passing that, here is a example of that...

var eventCopy = {};
for (var i in event) {
    eventCopy[i] = event[i];    
}

Then just send your function the eventCopy, even though this is a 'total' hack.

setTimeout(function () { yourFunction(eventCopy), yourDelayTime);

And voila it will work.

I should add, that Internet Explorer will merely create a reference to the global window event which is why we need the copy of event. This is because by the time setTimeout calls the function, windows.event has already passed,

Bottom line... don't try to send a event inside a setTimeout because IE won't accept it. This is true for IE 6, 7 & 8 from my testing.

I realize this question/answer is pretty old and seems to be resolved. That being said, I have another alternative I've used to handle a similar -- yet slightly different -- issue with 'Member Not Found' in IE versions prior to MSIE 9. I hope this helps someone out! ...this can also be used to work around issues with Firefox not having window.event.

First I extended jQuery and added a function to get the MSIE version or -1 if the browser is non MSIE. You can do the same or just create a pure JS function to accomplish this. Then create an event override function (it might be necessary to add a global 'event' variable in some cases), that's more of a per individual situation basis. Then override the event in your event handler(s) as needed.

Extending jQuery

// So this will give you the version of IE (or for non IE browser -1)
$.fn.msieVersion = function()
{
    if ( navigator.userAgent.toLowerCase().indexOf( 'msie' ) !== -1 ) {
        return document.documentMode; 
    }
    return -1;
};

Override the global event

var setEvent = function( evt ) {
    // Set the event if MSIE version is >= 9 or is -1 which means it's not IE
    if ( $.fn.msieVersion() >= 9 || $.fn.msieVersion === -1 ) { 
        // NOTE: I have a global 'event' variable I'm using that comes from another previously loaded JS file 
        // Why? I didn't do it. I'm updating some SUPER old code the best I can. (old enough it has references to Netscape....)
        event = evt || window.event; 
    }
    return true;
};

Usage Example

$( 'img.myImageID' ).bind('mouseover mouseout', function ( evt ) {
    setEvent( evt ); // Override the event
    // DO WORK! ...continue all other awesomeness here!
    // Maybe setTimeout(...)
};
发布评论

评论列表(0)

  1. 暂无评论