Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Created March 10, 2012 22:33
Show Gist options
  • Save jdjkelly/2013699 to your computer and use it in GitHub Desktop.
Save jdjkelly/2013699 to your computer and use it in GitHub Desktop.
Local links preventify
$(document).on("click", "a:not([data-bypass])", function(evt) {
// Get the anchor href and protcol
var href = $(this).attr("href");
var protocol = this.protocol + "//";
// Ensure the protocol is not part of URL, meaning its relative.
if (href && href.slice(0, protocol.length) !== protocol && href.indexOf("javascript:") !== 0) {
// Stop the default event to ensure the link will not cause a page
// refresh.
evt.preventDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment