2

i'm a javascript, jquery newbie :) how can i make a loop here on all the href within #rfr-topnav using javascript or jquery? thanks in advance.

    <script type="text/javascript">
$(document).ready(function(){
        var sel="#rfr-topnav a[href*='#root#']";
        var href=$(sel).attr('href');
        var rootUrl = $('#ctl00_RootUrlId').attr('value');
        var newhref=rootUrl+href.substr(href.indexOf('#root#')+6);
        $(sel).attr ('href',newhref);
});
</script>
1
  • Can you explain a bit more about the requirement? Commented Jan 11, 2011 at 11:27

1 Answer 1

1

Refactoring slightly, I think this is what you want:

$(document).ready(function(){
    var $sel = $("#rfr-topnav a[href*='#root#']");
    var rootUrl = $('#ctl00_RootUrlId').val();

    $sel.each(function() {
        var $this = $(this), href = $this.attr('href');
        $this.attr('href', rootUrl + href.slice(href.indexOf('#root#') + 6));
    });
});
Sign up to request clarification or add additional context in comments.

4 Comments

with the same how could i change a url from abc.com/radiofr/my/Person.aspx?accountname=radiofr\Administrateur to abc.com/radiofr/intranet/_layouts/rf.portal.web/…\Administrateur
use the string replace function
hmmm back after a while...i have just noticed that this script doesn't work in IE 7 or 8 but it works in firefox!
@user472285: In what way does it not work? Any error messages? A test page we can see?

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.