Babyz Babyz -3 years ago 96
jQuery Question

How to check if a specific link has been clicked(JS)

I'm making a chrome extension and what I want to happen is to alert the user if a specific link has been clicked on Facebook. And in my script every time I click a link it always alert accessing gma.

$(document).on("click", "a", function() {
//this == the link that was clicked
var href = $(this).attr("href");
if (window.location.protocol == 'https:'){
if(href == "gmanetwork"){
alert("Accessing Gma");

Answer Source

Code at Question assigns the value if (window.location.protocol = 'https:'){ "gmanetwork" to href using = operator at

if (href = "gmanetwork")

instead of checking the values for equality, use === operator

if (window.location.protocol === 'https:') {
    if (href === "gmanetwork") {
        alert("Accessing Gma");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download