Reputation: 161
I am creating a chrome extension
that sets the new tab page to my website (which is a replacement new tab page).
Once the redirect has occurred, I'd like the cursor to automatically be focused on the omnibox
or address bar
, so that the user can immediately start writing a URL or search query.
I'm sure this is possible because I have had chrome extensions in the past that allow this.
Anyone have any ideas how to go about it?
Upvotes: 1
Views: 856
Reputation: 77541
You're probably doing the new tab page replacement in a crude way - by intercepting a tab opening and redirecting it. In this scenario, as Haibara Ai mentions in a comment, it's not possible to focus on the omnibar.
Instead, you should create an override page in the manifest:
"chrome_url_overrides" : {
"newtab": "newtab.html"
},
This should be a local page, but you can embed your remote content using an iframe.
What's important is that override page will function the same as the normal one - the URL bar will be clear and the focus will be there by default.
Finally, think of the user experience when making a new tab reliant on remote content. You want the page to stay functional in case of a bad connection or offline browsing. Think of using offline techniques to remedy this, or having a local webapp that just pulls information off your site but renders independently.
Upvotes: 2