Skip to content

Instantly share code, notes, and snippets.

@sdball
Created July 15, 2011 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdball/1084638 to your computer and use it in GitHub Desktop.
Save sdball/1084638 to your computer and use it in GitHub Desktop.
Use jQuery to modify URLs that contain a specific string
<!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>
@sdball
Copy link
Author

sdball commented Jul 15, 2011

In production you'd probably want to extract the filter function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment