开发者

jQuery Propagation Firefox Bug?

This script is working perfectly with Chrome and Safari, but Firefox is bugging up for some reason:

<script type="text/javascript">
var $j = jQuery.noConflict();

$j(document).ready(function(){

    $j(function(){
        $j('.next').click(function() {
            location.href = $j(this).attr('href');
        });
        $j('.prev').click(function(){
            location.href = $j(this).attr('href');
        });

    });

    $j('body').keydown(function(event) {
        if(event.keyCode==82) {
            $j(document).trigger(location.href = '/?random');
        }
        if(event.keyCode==39) {
            $j('.next').trigger('click');
        }
        if(event.keyCode==37) {
            $j('.prev').trigger('click');
        }
    });

    $j('input, textarea').keydown(function(){
        event.stopPropagation();
    });

});
</script>

If you press left or right on your keyboard, it takes you to the next/prev page. If you hit R, it takes you to a random page. HOWEVER, if you are typing something in an input or textarea, the keyboard navigation is turned off (so the you can type without an unexpected page load if you hit R, left, or right).

It works great in Chrome and Safari, but in Firefox it bugs and the keyboard nav instead ONLY works if you're typing in an input or textarea. It does the opposite of what is intended.

I've disabled all add-ons in Firefox which didn't help. There have been a couple rando开发者_运维问答m times when it has worked properly, but I can't replicate them. I'm stumped as to why this isn't working in Firefox... any ideas? Thanks so much in advance!


You seem to be missing the event parameter in your function:

$j('input, textarea').keydown(function(){
    event.stopPropagation();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜