Reputation: 317
I have a series of links on a SharePoint page and am trying to modify one of the common URL parameters of them all. The links all look similar to this:
<a href="javascript:" onclick="javascript:RefreshPageTo(event, '/dev/Pages/stPCT.aspx?Paged=TRUE&p_ID=357\u0026PageFirstRow=31\u0026FilterField1=Number&FilterValue1=0000123450&&\u0026View={FC071FA0-12AA-7854-905E-0C4429FFFD52}&thisID=STRINGID');javascript:return false;" id="PagingLink" class="PagingLink">
Next</a>
What I am trying to get to happen is that the link is rewritten to change "thisID=STRINGID" to "thisID=0000123450"... So far I have tried (without success) the following.
$(".PagingLink").each( function(index,element) {
url = $(element).onclick();
console.log(url);
newurl = url.replace(/STRINGID/gi,"0000123450");
$(element).attr('href', newurl);
});
Any and all help would be greatly appreciated.
Upvotes: 3
Views: 3146
Reputation: 9
$(".PagingLink").each( function(index,element) {
url = $(element).onclick();
console.log(url);
newurl = url.replace(/STRINGID/gi,"0000123450");
$(element).attr('href', newurl);
});
Check This
$(".PagingLink").each( function(index,element) {
$(element).attr('href').replace(/STRINGID/gi,"0000123450");
});
.attr("value").replace('0', 'Day')
Upvotes: 0
Reputation: 4284
I'll do it like this:
$(".PagingLink").each( function(index,element) {
url = $(element).attr('onclick');
console.log(url);
newurl = url.replace(/STRINGID/gi,"0000123450");
$(element).attr('href',newurl);
});
Your mistake was in the .onclick, you should get it with attr() because it garantess you to get the correct value.
Upvotes: 4
Reputation: 9931
You need to change the text in the onclick attribute, not the href attribute. See this Fiddle: http://jsfiddle.net/fQEdV/2/
Changing the href won't dictate where the page will go since Sharepoint is using javascript to redirect the user in the click event for the link. If the user has javascript disabled, your script to update this url won't run for them anyways.
Upvotes: 0
Reputation: 43823
You are probably getting a JavaScript error with your current jQuery code, since there is no method called onclick()
. You can access the onclick value by using the attr()
method like so:
url = $(element).attr('onclick');
The rest of your code should execute correctly.
Upvotes: 1