[thelist] Using the simplest script possible (was: auto-replacing links...)
Joe Crawford
jcrawford at avencom.com
Tue May 22 11:53:39 CDT 2001
Mark Cheng wrote:
> all you need to do is access the links object, cycle through it and change
> the href, either using pattern matching or whatever.
Bingo!
> 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
> }
Eek! Simple is best! Don't be using that fancy schmancy getElement stuff
if you don't have to. A fine way to do this that will work in (almost?)
any damn browser would be: I think it would work as far back as
Netscape 2 or WebTV.
<script language="JavaScript" type="text/javascript">
<!--
var newLinkURL = "index.Jhtml"; // insert your URL
/* ======================================= */
/* this will change every link on the page */
/* to whatever newLinkURL is */
/* ======================================= */
function changeEveryDarnLink () {
for (i=0; i<document.links.length; i++) {
document.links[i].href=newLinkURL;
}
}
//-->
</script>
See, that way, you use the simplest method possible, and thus you won't
have to worry about detecting objects or whatnot.
- Joe <http://artlung.com/>
--
Joe Crawford |||||||||||||| mailto:jcrawford at avencom.com
|||||||||||||||||||||||| http://www.avencom.com
||||||||||||||||||||||||||| Avencom: Set Your Sites Higher
More information about the thelist
mailing list