Stop Event in IE 9 (without upgrading to Prototype 1.7)

对着背影说爱祢 提交于 2020-01-15 15:11:48

问题


The site I'm working on uses Prototype 1.6.1. Its Event.stop() doesn't work in IE9. I know that Prototype 1.7 fixes the problem. However, is there a walk-around if I cannot upgrade to Prototype 1.7?

I need the site to be compatible with IE 7, 8 and 9 (as well as Chrome, Firefox, etc).

Thanks!

EDIT: I tried event.preventDefault() and it doesn't work for me in IE 9. Here is an example: http://jsfiddle.net/garthcn/AdR7g/ It works in jsfiddle/Chrome/Firefox. If you paste the code to an HTML file and open it with IE9, it won't work.

EDIT2: I just found that Prototype 1.6.1 adds its own preventDefault() method to IE which doesn't work on IE 9. However, IE 9 comes with its own preventDefault() which actually works. So if I stick to Prototype 1.6.1, I guess I cannot get preventDefault() to work on IE 9.


回答1:


function stopDefAction(evt) {
     evt = evt || event;
     if (evt.preventDefault) {
          evt.preventDefault();
     }
     else {
          evt.returnValue = false;
     }
}



回答2:


It seems like internally Prototype does extend, which - under IE9 - breaks things. Without upgrading, the easy thing would be to add an x-ua-compatible meta tag at the tippy top of your head tag (but below the charset tag) to force IE9 into being IE less than 9.

If you have the ability, you could also try patching Prototype directly: http://mandagreen.com/prototype-1-6-event-stop-ie9-quick-patch/ This was written for 1.6.0, but I think it should work for 1.6.1. I have the same problem and will likely be trying it out to see what happens.



来源:https://stackoverflow.com/questions/8291805/stop-event-in-ie-9-without-upgrading-to-prototype-1-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!