I got help earlier here with what turned out to be a distribution problem, but now I'm trying to use HTML5 input autofocus , and now my code breaks.
Here is the code I'm working with:
<script type="text/javascript"> var $j = jQuery.noConflict(); $j(':not(form)').keydown(function(event) { $j('form').keydown(function(event) { event.stopPropagation(); }); if(event.keyCode==82) { $j(document).trigger(location.href = '/?random') } }); </script>
Basically, I have a keyboard setup. If you press R, this will result in a random page.
I tried to disable this functionality when the user entered text in the form / input field for obvious reasons. This code works, EXCEPT, when I try to use autofocus. If you start typing directly on the page, and the first letter you enter is R, it goes to a random page.
If another letter is first typed, then R is entered as a regular letter. Iβm kind of new to this, so any help is greatly appreciated! Thanks.
EDIT: upon further testing, it seems that the problem may not be autofocus, but mainly because only when the first letter that typed the letter is R, it crashes.
source share