3

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&amp;p_ID=357\u0026PageFirstRow=31\u0026FilterField1=Number&amp;FilterValue1=0000123450&amp;&amp;\u0026View={FC071FA0-12AA-7854-905E-0C4429FFFD52}&amp;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.

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I just tried adding "url = $(element).attr('onclick');" and it does not find anything.
are you sure that you've added after dom was created, inside $().ready(function(){}) ? Add it after all JS code. Maybe at the footer of the page.
1

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.

Comments

0

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.

Comments

0
        $(".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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.