Highlight URL bar using Chrome and Safari extension

与世无争的帅哥 提交于 2019-12-17 20:49:17

问题


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!


回答1:


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'.



来源:https://stackoverflow.com/questions/10492399/highlight-url-bar-using-chrome-and-safari-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!