467,104 Members | 1,055 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,104 developers. It's quick & easy.

Javascript dynamically change onkeydown event?

eboyjr14
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere!


Expand|Select|Wrap|Line Numbers
  1. // ==UserScript==
  2. // @name           iGoogle Suggest
  3. // @namespace      Devin Samarin
  4. // @description    This automatcally selects the top result for your query.
  5. // @include        *google.com/ig*
  6. // ==/UserScript==
  7. function makeRequest() {
  8.     GM_xmlhttpRequest({
  9.         method: 'GET',
  10.         url: 'http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&qu='+encodeURI(document.getElementById('q').value),
  11.         headers: {
  12.             'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
  13.         },
  14.         onload: function(responseDetails) {
  15.  
  16.             var response = responseDetails.responseText;
  17.             document.getElementById('q').value = response.split('["')[2].split('"')[0];
  18.         }
  19.     });
  20. }
  21. var quer = document.getElementById('q');
  22. quer.onkeydown = "alert('asa');";
onKeyDown = function() { ... };

onkeydown = function() { ... };

onkeydown = "...";

onKeyDown = "...";

onKeyDown = makeRequest;

onkeydown = makeRequest;
Jul 11 '07 #1
  • viewed: 5414
Share:
1 Reply
gits
Expert Mod 4TB
hi ...

add the onkeydown-eventhandling into a call from the onload-handler of the documents body ... during load the page is not fully rendered and the node is not available to be retrieved ... when you try it onload ... then the entire dom is loaded and document.getElementById finds your node and it will work then ;)

kind regards
Jul 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

22 posts views Thread by Mark Reginald James | last post: by
3 posts views Thread by Dunc | last post: by
6 posts views Thread by Alejandro Penate-Diaz | last post: by
2 posts views Thread by rockdale | last post: by
reply views Thread by =?Utf-8?B?QWJoaQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.