/    Sign up×
Community /Pin to ProfileBookmark

How do I get focus on the address bar and focus there?

When a website is loaded, is there anyway of using Javascript to get the address bar focus and delete the contents?

I’m not sure if there would be restrictions on doing this because of security reasons – but it would be helpful for me

Thanks

OM

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeJan 06.2011 — Not that I'm aware of.. sounds like it might be a security issue.. a malicious hacker causing an innocent website to redirect to his/her virus filled website..

Or I'm just paranoid.

^_^
Copy linkTweet thisAlerts:
@OM2authorJan 06.2011 — yes ur right

i'll tell u what i wanted it for: chrome

u open a new tab and u can just type on the address bar

i love it, it's great - i can use it to type an address or just use it to do a google search

now, recently, i found a *great* free homepage service: myfav.es

this gives u big icons to links u setup - i think it's great!

now, i found an extension for chrome that sets new tab pages to go to your myfav.es page - otherwise, it just give u ur recently opened tabs

all is great and wonderful: except for one thing!

when u open a new tab, the focus is not on the address bar ?

this really sucks

i'm use to doing 'ctrl t' to open a new tab and less than a split second later typing my url or search phrase

now, i have to move the mouse or press f6 - it's winding me up sooo much

so i hit upon the idea of using javascript to change the focus to the address bar

[B]surely it must be possible to change the focus at least and select all - but maybe not change the text?

[/B]
Copy linkTweet thisAlerts:
@WolfShadeJan 06.2011 — But the point is (and I'm not sure it CAN'T be done) that if you can put focus on the address bar, then you CAN manipulate the value of the address bar. So I'm thinking that it's not allowed to put focus on address bar to prevent someone from being able to alter the value of the address bar and redirect to a malicious site.

I could be wrong.

^_^
Copy linkTweet thisAlerts:
@OM2authorJan 06.2011 — yes, ur right

but for my frustrations, i wish i could have a solution!
Copy linkTweet thisAlerts:
@arnab1princeFeb 06.2015 — hi,

I am not sure how delete is going to work but you can get the focus like this:

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

addressBar.focus();
×

Success!

Help @OM2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...