How can I change every link on a page to something new?
Question:
How can I change every link on a page to something new?
Answer:
Iterate through each element in the document.links[] array, and change the .href property.
<script language="JavaScript" type="text/javascript"> <!-- var newLinkURL = "http://WebSanDiego.org/"; // 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>
CLICK THE BUTTON AT RIGHT, THEN CHECK THESE LINKS: |
Note: To get the undo feature on this page, I have some extra code, and a global array called "undo."