Created
March 10, 2012 22:33
-
-
Save jdjkelly/2013699 to your computer and use it in GitHub Desktop.
Local links preventify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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