I want to write a Firefox addon that could get the content of the address bar in real time, for example this addon will change every "a" to "A" just as the user pressed "a". The problem is that I couldn't find any way to do that in Javascript, is there a way to do it (getting the address bar content in real time)?
A Firefox extension can absolutely control the address bar. Try looking at the source code for the omnibar extension. (To get at the source code, install the extension and then poke around your Firefox profile folder)
If you are simply trying to modify the text of the address bar without redirecting the user, this is not possible.
Whenever a property of the location object is modified, a document will be loaded using the URL as if window.location.assign() had been called with the modified URL.
If the browser allowed you to use javascript to change the string in the address bar without redirecting the user, it would be prone to phishing. That's not what you're trying to do is it?
In JavaScript, window.location.href
will give you the value, and you could watch for it onkeyup, but AFAIK, you can't write back to the location field without loading the page at whatever value you set it to. What I mean is, if you did the following, it would reload the page:
window.location.href = window.location.href.toLowerCase();
I'm not familiar with how Firefox extensions work, but maybe there is a more "native" way to do this?
You didn't actually say at what point you're stuck.
First you need to create a simple extension that overlays the main browser window (browser.xul). Building an Extension - MDC, URL Fixer - good example extension
Then you'll need to attach an event listener to the URL bar (key words: addEventListener, events). You'll probably want to listen for "keypress", although you should read the documentation on various events available. You can search through Firefox or other extensions' source to see what element they attach the listener to. You can inspect the DOM tree (to see the elements available) in the DOM inspector extension.
In the event listener you should check and update the URL in the Location Bar (gURLBar.value, IIRC). You'll also have to do something to preserve the caret position.
Don't hesitate to ask for help in the forums listed at https://developer.mozilla.org/en/Extensions