Results 1 to 4 of 4

Thread: Java script for Keypress and the script to work

  1. #1
    Join Date
    Sep 2010

    Java script for Keypress and the script to work

    I need to assign a key in the javascript to actually make the javascript work,.

    I have a bookmark in chrome , a javascript , which actually works when clicked on it .,. but how can i edit it so that i can actually make it work on click a key or combination of keys.

    i want to declare the key or keycombo in the script itself .,.

    the script is for catching the selected text on the webpage and opening a new tab(or window) and doing an exact search search of the selected text using google.com .,.,

    So I want it to work it this way .,

    select the text
    press a key
    and it opens a new tab (or window) with an xact search .,.

    Thanks in advance ., pls help


  2. #2
    Join Date
    Feb 2010
    You just need to call your function and declare it below:

    onkeypress="{if (event.keyCode==13)yourfunction()}";
    The keycode ==13 will be the key Enter .

  3. #3
    Join Date
    Sep 2010
    will it work if it is in the bookmark .,., actually i've my script as a bookmark and it gets intialised only when it is clicked ,.,., so can u help in doing that .,.,

  4. #4
    Join Date
    Sep 2010
    Thanks for your reply for my question

    I'll elaborate my question.,.,.,

    I want the script to be used as a bookmarklet or an extension .,. since an extension is lil hard a bookmarklet with the javascript is fine .,.

    My Javascript bookmarklet already does this thing

    When text is selected and clicked on the bookmarklet it opens a new tab and does an exact search with the snippet of the text selected using google.com/search?q="(myselected text)"

    Now i want it to do automatically on a key press

    When certain text is selected and selected key is pressed it should do the work as when i clicked on the bookmarklet.

    Note: I'm using this bookmarklet in CHROME

    my javascript is
    javascript:a = "" + (window.getSelection() ? document.getSelection() : document.selection.createRange().text); if (a!=null)window.open("http://www.google.com/search?q=\"" + escape(a)+ "\"");

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center