Bet365 bonus - Anime Episodes - Buy WoW Gold - Self Improvement Articles Directory - Funbrain

PDA

View Full Version : Changing the href of all links on a page.


blueparukia
May 17th 2008, 6:59 pm
Basically, how do you do it?

I'd asume it has something to do with:

document.getElementsByTagName('a')

and a for each, but I am not sure exactly how that would work. Basically I want to change all the hrefs of all the links on my page to the same thing.

Thanks,

Josh

jnwms
May 17th 2008, 7:46 pm
I haven't had a chance to check this but it should work


for(x in document.links) {
document.links[x].href = 'yourlink.html';
}


this would change all the link on that page to the same url.

is that what you wanted to do

blueparukia
May 17th 2008, 8:59 pm
Aye, that is what I want it to do, but that code does not seem to work. I do have onlcick values for all my links too, so my current code is:


function lockLinks(){
for(x in document.links) {
document.links[x].href = 'http://google.com';
document.links[x].onclick = '';
}
alert("Links locked")
}

Thanks

jnwms
May 17th 2008, 11:30 pm
i've had a chance to have a look at the script and tested it in both IE and firefox and both seem to be working fine.

put the following code ina new .html file and have a look for yourself


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script>
function locklinks() {
for(x in document.links) {
document.links[x].href = 'javascript:void(0)';
document.links[x].onclick = '';
}
}
function dummyLinkFuction() {
}
</script>

<body>
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<a href="http://forums.digitalpoint.com/showthread.php?t=845622">link</a>
<br />
<input type="button" onclick="locklinks();" value="Stop Linking" />
</body>
</html>


Jon

jnwms
May 17th 2008, 11:48 pm
oh the dummy link function isn't ment to be opps

Jon