detecting ENTER keypress and click in Address Bar

N

newbiegalore

Hello everyone
I have just finished going through some tutorials on developing
extensions for mozilla and have made a version of the born-geek
toolbar. Being a newbie I am stuck at a relatively simple-sounding
problem and would greatly appreciate any pointers/examples..

The problem: I want to detect an ENTER keypress.
Why: I am developing an extension which should say the site you are
visiting is xyz.com. I can pick up the main URL using
alert(window.content.document.location.href); (thanks to people on
this forum!) but then I need to send it to my server and receive a
reply back. I want to pick up the URL only when an ENTER is pressed or
when the user clicks on the GO in the address bar.

Can someone please point me to a solution?

I checked up this forum and google groups, and did try out if the
keycode==13 thing, but I am confused about the fact that who should
call this function? This function should keep running in the
background irrespective of whether any toolbar buttons are clicked or
not. The same goes for detecting whether the GO key has been clicked.
How do I access this key? Is there a standard name/ID for it?

Thanks in advance,
-A
 
N

newbiegalore

Hello everyone
I have just finished going through some tutorials on developing
extensions for mozilla and have made a version of the born-geek
toolbar. Being a newbie I am stuck at a relatively simple-sounding
problem and would greatly appreciate any pointers/examples..

The problem: I want to detect an ENTER keypress.
Why: I am developing an extension which should say the site you are
visiting is xyz.com. I can pick up the main URL using
alert(window.content.document.location.href); (thanks to people on
this forum!) but then I need to send it to my server and receive a
reply back. I want to pick up the URL only when an ENTER is pressed or
when the user clicks on the GO in the address bar.

Can someone please point me to a solution?

I checked up this forum and google groups, and did try out if the
keycode==13 thing, but I am confused about the fact that who should
call this function? This function should keep running in the
background irrespective of whether any toolbar buttons are clicked or
not. The same goes for detecting whether the GO key has been clicked.
How do I access this key? Is there a standard name/ID for it?

Thanks in advance,
-A

any pointers would be appreciated! :)
 
J

Joost Diepenmaat

Agh! I don't want you to know what porn I'm viewing, so count me out as
a potential user of your extension, not matter what else it does. Also,
doing that kind of stuff may or may not be illegal, depending on your
user license and the count(r)y you're in. But I'm not (as they say) a
lawyer, so what do I know?

Everything outside of the web page is pretty much unstandardized and/or
restricted for security reasons. That includes any interaction with the
brower's location bar. Those security restrictions are there for good
reasons too.

Check your particular brower's documentation for extensions writers.

What function?

Wait what? Please read up on event based programming.

I've never even heard of a GO key.
 
N

newbiegalore

Agh! I don't want you to know what porn I'm viewing, so count me out as
a potential user of your extension, not matter what else it does. Also,
doing that kind of stuff may or may not be illegal, depending on your
user license and the count(r)y you're in. But I'm not (as they say) a
lawyer, so what do I know?


Everything outside of the web page is pretty much unstandardized and/or
restricted for security reasons. That includes any interaction with the
brower's location bar. Those security restrictions are there for good
reasons too.


Check your particular brower's documentation for extensions writers.


What function?


Wait what? Please read up on event based programming.


I've never even heard of a GO key.

Thanks for the comments Joost :) . I should have phrased the problem
better. The thing is that when I make a webpage, say with a button on
it, I can link the click event of that button to some script which
will perform an action. I can write a script to check if a keypress
was ENTER or not. The problem I am facing is that I don't know "which-
webpage-element/who" should call this function when I write an
extension for firefox.

I can write a keycode checking function in an JS file which will be
linked to the toolbar elements, but the function needs to be run by
someone. Maybe when the extension loads or something. I read up on
event based programming, and even if I use something like, <input
type="submit" name="clickme"
value="Click Me!" onclick="alert('Thank You!')"/> , the onclick/onload/
whatever.. is called when an object event happens to an object.

I want that the keycode checking function should keep on running
irrespective of whether the user is using the scroll bars/clicking/
etc..

If you have any specific tutorial/pointer in mind it would be a great
help.
Thanks,
PS: the GO buton I was refering to is the green "play" button beside
the address bar in firefox. :)
 
N

newbiegalore

Thanks for the comments Joost :) . I should have phrased the problem
better. The thing is that when I make a webpage, say with a button on
it, I can link the click event of that button to some script which
will perform an action. I can write a script to check if a keypress
was ENTER or not. The problem I am facing is that I don't know "which-
webpage-element/who" should call this function when I write an
extension for firefox.

I can write a keycode checking function in an JS file which will be
linked to the toolbar elements, but the function needs to be run by
someone. Maybe when the extension loads or something. I read up on
event based programming, and even if I use something like, <input
type="submit" name="clickme"
value="Click Me!" onclick="alert('Thank You!')"/> , the onclick/onload/
whatever.. is called when an object event happens to an object.

I want that the keycode checking function should keep on running
irrespective of whether the user is using the scroll bars/clicking/
etc..

If you have any specific tutorial/pointer in mind it would be a great
help.
Thanks,
PS: the GO buton I was refering to is the green "play" button beside
the address bar in firefox. :)

OK got it.. I used ..

function kH(e) {
var pK = e? e.which: window.event.keyCode;
if (pK == 13 ){
alert('Enter was pressed');
}
}

document.onkeypress = kH;
from: http://javascript.about.com/library/bltut33.htm

Can someone please point me to how to understand if the "go" button in
the address bar has been clicked. The go button is the one where the
following tooltip is displayed "Go to the address in the Location Bar"

Thanks,
 
V

VK

Hello everyone
I have just finished going through some tutorials on developing
extensions for mozilla and have made a version of the born-geek
toolbar. Being a newbie I am stuck at a relatively simple-sounding
problem and would greatly appreciate any pointers/examples..

Where the one could be to use the appropriate newsgroup. It is not a
"go away!" message, but clj is primarily targeted to cross-browser
development for the Web. XPCOM and internal Gecko JavaScript layer
questions for privileged extensions are not really within this domain.
You should ask at mozilla.dev.tech.javascript

You may also look through http://developer.mozilla.org/en/docs/XUL and
http://www.xulplanet.com/
Both are a complete permanent mess for years, so some patience will be
needed.
 
M

Mr Shore

OK got it.. I used ..

function kH(e) {
var pK = e? e.which: window.event.keyCode;
if (pK == 13 ){
alert('Enter was pressed');

}
}

document.onkeypress = kH;
from:http://javascript.about.com/library/bltut33.htm

Can someone please point me to how to understand if the "go" button in
the address bar has been clicked. The go button is the one where the
following tooltip is displayed "Go to the address in the Location Bar"

Thanks,

seems ENTER's keyCode is 28
 
N

newbiegalore

seems ENTER's keyCode is 28

Thanks VK.. appreciate the pointer :)

Mr. Shore, I tried it out and it works man. 13 seems to be the ENTER
code. I am using firefox 2.0.0.13.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top