When the focus is in some other places in Firefox, such as the address bar, what keyboard shortcut I can use to move the focus back to the webpage (so I can use shortcuts like Page Down
to navigate the page)?
6 Answers
What keyboard shortcut can I use to move the focus back to the webpage?
Alt+D , then press Tab twice (or three times):
Get "focus" on webpage for in-page keyboard navigation. Note the dotted frame around the page.
-
Or may be one time for Firefox 57 with only one unified address and search box?– xuhdevCommented Oct 19, 2017 at 23:18
-
@xuhdev Possibly. I'm running v56. First tab goes to the tab bar, second to the page context.– DavidPostill ♦Commented Oct 20, 2017 at 5:07
The answer depends on whether you typically have a sidebar open. tl;dr:
- Tab (if no sidebar is open, or if sidebar is on the right)
- F6F6 or ShiftF6 (if sidebar is on the left)
- CtrlF and then Escape (works regardless of sidebar position, avoids problem with page scroll position jumping around)
- The
javascript:
shortcut hack from this answer also works in Firefox: https://superuser.com/a/324267/143467
In Firefox 57 the search bar is gone by default. If you do not have a sidebar open then pressing Tab once returns focus from the address bar to page content (as @DavidPostell and @xuhdev suggested in the other answer). But using Tab often has a side-effect of causing the page scroll position to jump around.
F6 (Move to Next Frame) also works. I had hoped that F6 would avoid making the page jump around, but it turns out that is not the case.
If you use a sidebar then things are more complicated. I usually have the Tree Style Tabs sidebar open, and I have to press Tab four times to get focus back to the page content. I can press ShiftTab twice, but that has a side-effect of scrolling the page to the bottom. On the other hand, pressing F6 twice reliably cycles to the sidebar and then to the page.
You can move the sidebar to the right side of the browser to change the order of elements/frames that F6 and Tab cycle through. If the sidebar is on the right, then pressing F6 or Tab once moves focus from the location bar to the page, just as if there were no sidebar open.
My ideal would be to customize Firefox so that pressing Escape moves focus to the page. But I have not found a way to do that.
If you toggle the left-side panel for history or bookmarks, the focus shifts back to the webpage, i.e., <Ctrl+B><Ctrl+B> or <Ctrl+H><Ctrl+H>
Like in Chrome (found here) you can set a favorite in Firefox to be the web address of:
javascript:
And if you hit Enter on javascript:
in the URL bar, it'll return focus back to the page. I added a tag 'u' and keyword 'u' so that it brings up the bookmark.
Here's what I did:
bookmarks > right-click > add bookmark:
name: u
url: javascript:
tags: u
keyword: u
as @jesse hallett mentioned escape would be ideal. or a way to customize this (fj
anyone?)?
-
1I've been using this trick for years in Chrome and later in Brave. Recently had to start using Firefox more. What I hate about it, that in Chrome (if you're in the address bar) when pressing
u
(as in your example), it would simply move the focus back to the page without affecting the URL in the bar. In Firefox, it also changes the address to "javascript:"– iLemmingCommented Apr 20, 2023 at 4:55
At the time I'm writing this answer, ShiftF6 works on Chrome and Firefox with Windows.
-
3Is there any point in repeating an existing answer? Please read the help on how to answer questions. Commented Jan 28 at 12:28
for people later here, we can use shortcut custom get a better and elegant way.
firstly follow this answer to set the base of custom shortcuts: Then use some trick from firefox which allow us to run script code inside this content webpage, named message Manager, you can click the link to see details of this.
let urlBar = window.document.getElementById('urlbar-input')
urlBar.addEventListener('focus', event => {
let focusURLBar = window.document.getElementById("focusURLBar")
focusURLBar.removeAttribute('command')
focusURLBar.setAttribute('oncommand', 'window.gBrowser.selectedBrowser.messageManager.loadFrameScript("data:,content.focus();", true)')
})
urlBar.addEventListener('blur', event => {
let focusURLBar = window.document.getElementById("focusURLBar")
focusURLBar.removeAttribute('oncommand')
focusURLBar.setAttribute('command', 'Browser:OpenLocation')
})
Here we basically get the object of search bar which will focus when we input on it or press cmd + L
, so we can add a focus
and blur
event listener here to change the behavior of cmd + l
, if you want use a different shortcuts for back to webpage just following the answer quoted before.
And since we just need this work at browser.xhtml loaded, we warp that into a regex condition, then it should works smoothly.
here is the full config.cfg
file:
// -*- mode: javascript; -*- vim: set ft=javascript:
"use strict";
(() => {
if (Services.appinfo.inSafeMode) {
return;
}
const chromeAddressPattern = new RegExp(
"^chrome://browser/content/browser\\.xhtml$");
const addressPattern = new RegExp(
"^(chrome:(?!//(global/content/commonDialog)\\.xhtml)|about:(?!blank))"
);
Services.obs.addObserver(subject => {
const namespaceID = "autoconfig_" + subject.crypto.randomUUID().replaceAll("-", "_");
subject.addEventListener(
"DOMContentLoaded",
event => {
const document = event.originalTarget;
const window = document.defaultView;
if (!addressPattern.test(window.location.href)) {
return;
}
let mainKeyset = window.document.getElementById("mainKeyset")
if (chromeAddressPattern.test(window.location.href)) {
let urlBar = window.document.getElementById('urlbar-input')
urlBar.addEventListener('focus', () => {
let focusURLBar = window.document.getElementById("focusURLBar")
focusURLBar.removeAttribute('command')
focusURLBar.setAttribute('oncommand', 'window.gBrowser.selectedBrowser.messageManager.loadFrameScript("data:,content.focus();", true)')
})
urlBar.addEventListener('blur', () => {
let focusURLBar = window.document.getElementById("focusURLBar")
focusURLBar.removeAttribute('oncommand')
focusURLBar.setAttribute('command', 'Browser:OpenLocation')
})
}
// other shortcuts modify here
},
{ once: true }
);
}, "chrome-document-global-created");
})();