Changing the link target of a whole page or table?

windows

Guest
Is there any way to change the target of every link on a page including all the links in the tables on the page? Maybe via a style sheet?<!--content-->not unless you use a find/replace function in a text editor.<!--content-->of course there is, you can do this in run time using javascript, but I am not sure this is what you are looking for ? (e.g. it is not a permanent change to your page, only during the specific run/view of the page).<br />
<br />
Just put following javascript on your page:<br />
<br />
<script language="javascript"><br />
<br />
function replinks(){<br />
for (var i=0;i<document.links.length;i++){<br />
document.links.href = 'http://www.htmlforums.com/archive/index.php/mypage.com/'<br />
}<br />
}<br />
<br />
</script><br />
<br />
<br />
Just call the function replinks() at any time and all links are replaced and now pointing to "mypage.com/"<br />
<br />
You can also do more intelligent search / replace:<br />
<br />
function replinks(){<br />
for (var i=0;i<document.links.length;i++){<br />
var href = <!-- m --><a class="postlink" href="http://www.htmlforums.com/archive/index.php/document.links">http://www.htmlforums.com/archive/index ... ment.links</a><!-- m -->.href;<br />
if (href.indexOf('disney.com') >= 0){ <br />
document.links.href = 'http://www.htmlforums.com/archive/index.php/6flags.com/';<br />
}<br />
}<br />
}<br />
<br />
<br />
Or to replace a domain name with another domain name without affecting the page/directory settings, etc:<br />
<br />
function replinks(){<br />
for (var i=0;i<document.links.length;i++){<br />
var href = <!-- m --><a class="postlink" href="http://www.htmlforums.com/archive/index.php/document.links">http://www.htmlforums.com/archive/index ... ment.links</a><!-- m -->.href;<br />
newref = href.replace('mydomain.com','newdomain.com');<br />
document.links.href = <!-- m --><a class="postlink" href="http://www.htmlforums.com/archive/index.php/newref;">http://www.htmlforums.com/archive/index.php/newref;</a><!-- m --><br />
}<br />
}<!--content-->ahh thanks KD, leave it to javascript.<br />
<br />
but to the question about a style sheet, that answer is no :)<!--content-->Yes, using style sheets you can not (would not make any sence if you could !!!)<br />
<br />
Besides, I get the feeling this is not excactly what Dave was after to begin with !!<!--content-->
 
Back
Top