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
精彩评论