Skip to content

Instantly share code, notes, and snippets.

Created Jul 15, 2011
What would you like to do?
Use jQuery to modify URLs that contain a specific string
<!DOCTYPE html>
<meta charset="utf-8">
<title>Rewriting UR Links</title>
<h1>Rewriting UR Links</h1>
<a href="">Link to that opens in a new tab/window.</a>
<a href="">Link to that opens in the same window.</a>
<script src=""></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("") != -1;
}).attr('target', '_blank');
Copy link

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