问题
IE9 is still in Beta, but all the same, here is a question:
Using prototype.js 1.6.1, proper form for adding a click event to a link, and override the default link behavior, would be:
mylink.observe('click', function(e){
doSomething();
e.stop();
});
While this works perfectly in every other browser that I tried, IE9 is a unique case. The default event behavior fires and my link takes me to the linked location. It seems that stop()
isn't doing its job in IE9.
The following code works perfectly in IE9:
mylink.onclick = function(){
doSomething();
return false;
}
Any idea what I could do to fix the prototype methodology for use in IE9?
回答1:
prototype.js versions less than 1.7 does browser-sniffing to apply cross-browser compatible fixes.
prototype.js overwrites the native methods with it's implementation, which fails in IE 9; even-though it has support for DOM Level 2 Events.
The newer version of prototype.js doesn't have this issue as it does 'feature detection' rather than 'browser-sniffing'
回答2:
Change document mode to IE8 standards by putting the following tag inside <head></head>
:
<meta http-equiv="X-UA-Compatible" content="IE=8" />
来源:https://stackoverflow.com/questions/3919250/disable-a-link-in-ie9-prototype-stop-not-working