Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

javascript - Highlight URL bar using Chrome and Safari extension

Is it possible to highlight the URL bar (set focus to the location bar) using Google Chrome extensions or Safari extensions?

Using Firefox extensions, one can highlight the URL bar like this:

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

I'm not sure if there's similar functionality in Chrome and Safari.

Thanks in advance for your help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Firefox, in its plugins and extensions gives access to browser's "chrome" (the UI stuff around the page) which makes this possible, although I am not sure of the api that you have mentioned.

Google Chrome, however, is clear about its exposure to browser's chrome to the extension and gives access only through browser actions and page actions. Moreover you can use HTML5 Desktop Notifications, Context Menus and Omnibox to get more out of the browser.

But I am afraid you cannot access the address bar from extensions (or otherwise) which Chrome explicitly denies access to via javascript or Extensions.

At most what you can do is to point it out to user that pressing Ctrl+L will get them to browser's address bar or if you want to redirect the user you can use window.location.href = 'https://stackoverflow.com'.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...