jquery - Chrome plugin - detect if an anchor tag was clicked -


i writing chrome extension needs determine whether anchor tag on current page has been clicked or whether page refreshed.

all code goes in content script executes each time page refreshed.

i have tried using

if($('a').data('clicked')); 

but reason returning undefined.

i can't use

$('a').click(function(){...}); 

because need have else clause in code executes if link not clicked.

to sum up: want if/else statement in chrome extension using jquery executes code if link clicked , if not clicked.

you bind click listener, set flag, , bind beforeunload event called before refresh.

var clicked = false;  $('a').click(function(){     clicked = true; );  $(window).on('beforeunload', function() {      if (clicked == true) {       // link clicked... execute code     } else {        // no link clicked... execute other code     }  }); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -