开发者

Google Chrome Extension Running in the background

I am trying to make a google extension that basically checks the current tab URL to see if the URL is our prefix, so far I have this in my background.html (I have tab and background permissions set in my manifest):

<script type="text/javascript">
        chrome.tabs开发者_开发知识库.getSelected(null, function(tab) {
            alert(tab.url);
            if(tab.url == "http://www.google.com") {
                alert("YOU'RE AT GOOGLE");
            }
            //changeTabURL(tab.url, tab);
        });
</script>

So this seems to run only when I first load the extension, it tells me "chrome://extensions" and then it disappears. How do I get it to check each time the user goes to a new URL? Is this possible?

Thanks!


chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if(changeInfo.status == "loading"){ 
        //do url check
    }
});


use the following:

chrome.tabs.onUpdated.addListener(function(Tab tab) {...});

See the documentation here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜