Rewrite Relative URLS with JQuery, or Javascript
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 re开发者_如何学Pythonlative 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.
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.
精彩评论