Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

internet explorer - Member not found IE error (IE 6, 7, 8, 9)

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 relavent. Any help is greatly appreciated.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...