Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to move focus to browser address bar? [duplicate]

Tags:

javascript

With Safari, if I set it to open new tabs as blank, when I hit cmd-T, my cursor is in the address bar, ready to type a URL or search.

If I set it to go to a homepage, the cursor does not immediately go to the address bar and I have to hit a keystroke.

Is there a Javascript I can put on my homepage (I'm the only one who uses it - usual "bookmark" page) so that when I visit that page, my focus (cursor) automatically goes to the browser's address bar?

I could add a search box but sometimes I want to type a URL directly.

like image 707
raindog308 Avatar asked Jan 16 '16 17:01

raindog308


1 Answers

I don't think you can do that, but as you've said it's a "link page", you can put an input on the page that you type the address into, then use a button (or keypress) to do location = yourInput.value; which will take you to the URL you typed in. That won't have omnibox functionality (not unless you get fancy with your JavaScript and integrate it with a Google custom search engine, etc.), but for the "just type in a URL" use case, it'll work.

Alternately, the Google Custom Search Engine (if you like searching with Google) is pretty easy to drop on a page, and you can get an event when the user confirms, which you could use to check if the search input has a URL as opposed to a search in. Kind of roll-your-own omnibox. (Not touting for Google, but doing a CSE is quite easy: Create it with your Google account, drop some script on your page, add a bit of markup, and that's pretty much it. Don't know if Duck Duck Go and such offer the same sort of thing.)

like image 118
T.J. Crowder Avatar answered Sep 21 '22 22:09

T.J. Crowder