开发者

Why are there no raptors in IE?

The other day, SmashingMagazine gave the world a wonderful gift. Unfortunately IE (at least IE7) to my shock and amazement, has a problem with it. Does anyone know why the code below would not fire properly in IE7?

It listens for keypresses and fires a function if it can match the konami code. I'm not super knowledgeable on JS events, so any direction would be appreciated.

var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
            $(window).bind("keydown.raptorz", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 ) {
                    init();
开发者_JS百科                    $(window).unbind('keydown.raptorz');
                }
            }, true);

EDIT: Can anyone else test this in IE7 to confirm?


jQuery supports e.which for the keyCode just in case e.keyCode doesn't work. So try change e.keyCode to e.which.

But i think it is the true as the third argument in the bind. Take that away and try again.

Here is my copy in JS fiddle of a IE compliant version: Link

UPDATED: wow, the bind for keydown on $(window) wasn't working for IE and $(document.body) wasn't working for FF, so I did $(document) and it works for both....

The link above now has a version that works for both FF and IE at least.


I don't have IE handy, but I'd bet it's keyCode tripping you up - I believe you need to do something like this to get the proper key code in a cross browser fashion:

var keyPressed = e.keyCode ? e.keyCode : e.charCode;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜