Stop Event in IE 9 (without upgrading to Prototype

2019-08-02 18:55发布

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.

2条回答
趁早两清
2楼-- · 2019-08-02 19:21
function stopDefAction(evt) {
     evt = evt || event;
     if (evt.preventDefault) {
          evt.preventDefault();
     }
     else {
          evt.returnValue = false;
     }
}
查看更多
我想做一个坏孩纸
3楼-- · 2019-08-02 19:24

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.

查看更多
登录 后发表回答