Search code examples
javascripteventsdom-eventsonbeforeunload

Javascript, determine if an href click is a call to javascript function or not


I'm tying in to the onbeforeunload event in Javascript to disable control of the page during the unload process. We have a bunch of users who were editing data during this time and it was wreaking havoc on the product.

There are a bunch of links that show up on the page that have href="javascript:.....".

Clicking these links fires the disabling code, which makes the page impossible to use. Is there a way I can detect if the onbeforeunload event is navigating to a different page or just firing this Javascript?


Solution

  • This isn't the most reliable way of checking for this but it works for my purposes:

    $('*:focus').attr('href')