Created
July 15, 2011 13:07
-
-
Save sdball/1084638 to your computer and use it in GitHub Desktop.
Use jQuery to modify URLs that contain a specific string
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Rewriting UR Links</title> | |
</head> | |
<body> | |
<h1>Rewriting UR Links</h1> | |
<p> | |
<a href="http://na8.salesforce.com/something">Link to http://na8.salesforce.com/something that opens in a new tab/window.</a> | |
</p> | |
<p> | |
<a href="http://xyzzyb.com">Link to http://xyzzyb.com that opens in the same window.</a> | |
</p> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
jQuery(document).ready(function($) { | |
// Stuff to do as soon as the DOM is ready. Use $() w/o colliding with other libs; | |
$('a').filter(function() { | |
return this.href.indexOf("na8.salesforce.com") != -1; | |
}).attr('target', '_blank'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In production you'd probably want to extract the filter function.