5

I'm developing an extension that requires to set focus to the address bar at some point. I've been trying to RTFM, but the FM is so hard to read!

Does anyone know of any way to set focus to the address bar from within a firefox extension?

TIA.

Rakesh Pai
  • 26,069
  • 3
  • 25
  • 31

1 Answers1

3

I would imagine it would be something like:

var addressBar=document.getElementById('urlbar');
addressBar.focus();

assuming document is in the XUL Chrome context.

I haven't tested that yet though, so I'm not 100% yet.

lucideer
  • 3,842
  • 25
  • 31
  • Thanks, lucideer. Any idea where I can find the documentation for such elements on the chrome? Thanks again. – Rakesh Pai Jul 16 '10 at 15:12
  • Just use the DOMInspector extension - it lets you browse the XUL chrome DOM. – lucideer Jul 16 '10 at 15:34
  • 1
    A simple but very handy time-saver when using DOM Inspector is https://addons.mozilla.org/en-US/firefox/addon/3276/ -- the install.rdf says it's not compatible with 3.6.6 but it actually works fine, as far as I can tell. – Tyler Jul 17 '10 at 00:40
  • 4
    You can also just load chrome://browser/content/browser.xul in FF and use Firebug to inspect the DOM. Though it's funny to see the browser in the browser. – i_am_jorf Jul 23 '10 at 17:41
  • `urlbar` doesn't seem to be present any more (Firefox 66). – Pistos Jun 03 '19 at 00:36
  • 1
    @Pistos yes this question was about XUL extensions in Firefox which have not been supported since Firefox 57. See this announcement https://blog.mozilla.org/addons/2016/11/23/add-ons-in-2017/ – lucideer Jun 18 '19 at 09:44
  • @lucideer: Any tip for focusing the address bar in modern Firefox extensions, then? – Pistos Jun 18 '19 at 22:08
  • @Pistos I may be wrong, but I believe this is no longer possible, which seems to be an intentional decision on Mozilla's part, for consistency/security/similar. Can't find a definitive reference though, so I'm open to correction. – lucideer Jun 19 '19 at 17:35
  • 1
    All I want to do is create a new tab, then focus the cursor on the address bar. Since I can't do that, I have to create the tab (Ctrl-T), then manually focus (Alt-D). I can't see at the moment why it would be a security concern to allow extensions to focus the address bar. – Pistos Jun 20 '19 at 04:06