[thelist] auto-replacing links (was: Pop-up when user leaves site)

Mark Cheng mark.cheng at ranger.com.au
Mon May 21 21:57:07 CDT 2001


>>>> Now, I have a question.  Is it possible to write a JavaScript function
>>>that
>>>> will automatically change every link on a page to point to
>>>somewhere else
>>>> (just like "index.jhtml").  It would be pain to do this manually...


sure - its easy if you want to make the same replacement in every link ie -
foo.html to foo.Jhtml.

all you need to do is access the links object, cycle through it and change
the href, either using pattern matching or whatever.
Depending upon platform etc you may need cross browser code.  below find
some code for latest gen browsers :

function changeLinks () {
var links = document.getElementsByTagname("A");
for (i=0; i<links.length; i++) {
	insert code to identify and replace strings here
}

hth

MarkC


This email may be confidential and contain commercially sensitive information.  Only the intended recipient may access or use it.  If you are not the intended recipient please delete this email and notify us promptly. 
We use virus scanning software but exclude all liability for viruses or similar in this email or any attachment.






More information about the thelist mailing list