Sunday, 18 August 2013

Detecting whether a page is https or not in a Chrome Extension?

Detecting whether a page is https or not in a Chrome Extension?

I'm trying to come-up with a way that, when the pop-up button of a Chrome
Extension is clicked, the extension checks whether the current tab is
https.
If it is, display an alert and then break or don't run the next function.
If it isn't, then do nothing (as in, don't display the alert and run the
extension normally)
I tried
if (window.location.protocol === 'https:') {
alert("NO");
In the popup.js but it doesn't seem to be working. Variations either just
display the popup somehwere in the corner and the extension keeps working,
or nothing happens.
Is there an inherent way of doing this with the Chrome API?

No comments:

Post a Comment