I'm looking to optimize the code below in order to replace each link's href querystring with the current page URL's querystring if the current page URL has an argument 'myid1' or 'myid2' in the querystring. I want this script to execute as quickly as possible. Any assistance would be greatly appreciated. Thank you in advance :)
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script type="text/javascript">
$(function() {
var requestid = gup('myid1');
if (requestid) {
$("a.rewrite").each(function() {
var base = this.href;
var pos = base.indexOf("?");
if (pos != -1) {
base = base.substr(0, pos);
}
this.href = base + "?myid1=" + requestid;
})
}
var requestid2 = gup('myid2');
if (requestid2) {
$("a.rewrite").each(function() {
var base = this.href;
var pos = base.indexOf("?");
if (pos != -1) {
base = base.substr(0, pos);
}
this.href = base + "?myid2=" + requestid2;
})
}
})
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
</script>
<a href="http://www.website.com/?someid=1234" class="rewrite">Hyperlink</a>