View Full Version : changing href for all <a> tags on the webpage
manjeet799
11-09-2006, 07:41 AM
Hi ,
I want to change the href for all the <a> tags once the page has full loaded.
Is there any way to do it.
Regards
Manjeet
yes, is the simple answer.
What you want to change them to will depend how exactly it's done, but the start point regardless will be something like:
window.onload = function() {
var links = document.getElementsByTagName('a');
for(i=0;i<links.length;i++) {
links[i].href='http://www.google.com';
}
}
I'm assuming that changing all the links on a page to the same thing isn't what you want to do...it would be rather pointless...but instead, you want to add something to the end of all the urls?
links[i].href+='?referrer=1234';
if your links might already have a querystring (the ? and everything after it) then you won't want the 2nd ? added, but I'm sure you can work that out :)
manjeet799
11-09-2006, 08:36 AM
thanks very much for the quick reply.
I want to change some part of the url
Regards
Manjeet
manjeet799
11-09-2006, 09:46 AM
I want to replace the url http://localhost/global/en/homepage.htm by
http://localhost/ae/ar/homepage.htm
i.e. to replace global/en by ae/ar
When I read the links[i] array it does not match the string due to /
Please suggest some method
Regards
Manjeet
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.