0

I work for a company who builds websites on a platform.

We are running into a problem with relative urls. The entire platform we use, uses relative URLS and I need to be able to rewrite them, but I only have access to JQuery or Javascript.

The header and footer of our website is being included on another website, so it is messing up the relative links. If we can rewrite them to absolute, then that will fix everything.

(right now the relative link is showing up as sub.domain.com/page I need it to be domain.com/php)

I need to rewrite the urls from /page to domain.com/page but only in certain div containers

"#div1"

"#div2"

"#div3"

Please help. Thanks! If you think you could help but need more information, I can try to explain better as well.

1 Answer 1

3

You mean "#div1 a" right?

Maybe this is a valid solution:

var newDomain = "http://new.domain.com";

$("#div1 a, #div2 a, #div3 a").each(function(){
    var href = newDomain + $(this).attr('href');
    $(this).attr("href", href);
});

Try it and tell me about if it works. :) Bye.

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

2 Comments

No need to wrap this in a jQuery object ... just get and set this.href (Make sure to check that it's not undefined first.)
Yeah, it's a good point. But maybe can turn incompatible with old browsers like IE. if I'm not mistaken, .href on IE return absolute path, and others browsers only relative (when applicable).

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.