开发者

How to send an alert in chrome extensions?

开发者 https://www.devze.com 2022-12-17 10:05 出处:网络
I am trying to get some experience with chrome extensions. I have a question though. Let\'s say I am writing an extension that everytime you see the word (wow) in the url, i will alert the user with a

I am trying to get some experience with chrome extensions. I have a question though. Let's say I am writing an extension that everytime you see the word (wow) in the url, i will alert the user with a red page that they have to click on accept to pass, or an alert box that they have to get through in order to see the page, how would i:

1) get the url of the page 2) make the red alerting page, or the alert box w开发者_开发百科ithout the need for the user to actually go click at the extension's icon to get information?

Thank you so much


It's certainly late, but I thought I'd answer anyway. What you need is a content script. You can set it to match on certain domains and then do a more granular filter inside the script checking against window.location and alerting/displaying a div layer for matched URLs. The content script has full access to the page DOM so you can easily hide or dim it and show a warning.


Can also be done using chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){})... API. One can find if(tab.url.indexOf("www.wow.com") > -1){ //do things here }

0

精彩评论

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