开发者

Get URL from current tab in Chrome when the extension is open?

开发者 https://www.devze.com 2023-01-06 05:13 出处:网络
I can get the URL of the current tab if I click on my extension. But if the extension is already open (user clicks on link that loads a webpage in the current tab, I don\'t get the current url.)

I can get the URL of the current tab if I click on my extension. But if the extension is already open (user clicks on link that loads a webpage in the current tab, I don't get the current url.)

Here is the code I am using:

<script> 
           window.addEventLi开发者_如何学编程stener("load", windowLoaded, false);
        function windowLoaded() {
          chrome.tabs.getSelected(null, function(tab) {
         document.getElementById('currentLink').innerHTML = tab.url;
          });
        }
</script>

    <div id="currentlink">Url will appear here</div>


If you want to see if a page is loaded in extensions, within your extension page (such as background, popup, etc), not content script, make use of the tab events that Chrome Extensions gives:

http://code.google.com/chrome/extensions/tabs.html#event-onUpdated

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号