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
Post a Comment