Chrome Extension That Launches From An HREF click?

We're building a chrome extension for our corporate environment. When the user is browsing the web, if they click on a link, the extension should view the link and prompt the user a warning if the link is for a site that we have a business relationship with and warn them so (and in a few rare circumstances prevent them from going to the link).

We created an extension that's appears as a button on the toolbar and when the user clicks on it a popup appears. So that's good. Now we want to get rid of the button and have it invoked when the user clicks on a link on whatever webpage they're viewing. The extension would then read the link and decide if should prompt the user. How is this done though? How can we make the extension override all href clicks?

(Note, we're not currently concerned about when they type in the web address manually or click on a link from outlook, for reasons that are beyond the scope of the question)

Thanks

Answers


This is fairly simple to do. Inject a content script onto every web page that does something like this:

var anchors = document.querySelectorAll('a')
for (var i=0; i<anchors.length; i++) {
    anchors[i].addEventListener('click',function(event) {
        if ( /* check here if a partner link */ ) {
            // issue some warning to user
            event.preventDefault()
            event.stopPropagation()
        }
    })
}

Need Your Help

MFC CComboBox OnKillFocus/ShowDropDown after SetCurSel on Windows 7

c++ mfc windows-7 ccombobox onkillfocus

As you may know a CComboBox (DropDownList style) only selects properly by typing if you don't let it autosort it's content. Here an example of what i mean:

python regular expression get numbers except decimal

python regex

I want to get the greater than or equal to 6 digit number, but ignore the decimal. For example: