Link to home
Start Free TrialLog in
Avatar of AntoniL
AntoniL

asked on

Many links with the same Target

Hi lads,
I've got, say, 2 links with the same target, such:

<a href="hello.htm#1" target="MyIFrame2">Bookmark 1</a>
<a href="hello.htm#2" target="MyIFrame2">Bookmark 2</a>

Now, is there any way I could use a CSS or whatever to specify that all these links have the same target?, I just want to get rid of the target="MyIFrame2" bit. I know it sounds stupid but I'm writing a 1MB HTML (with hundreds of links with the same target) page and trying to get rid of as much text as I can. To make things more difficult, I've got two frames, left & right, with an IFRAME on each page. The links you see above go into the first IFRAME, and try to bookmark on the second IFRAME. Is that clear?, hope so ...
Any ideas guys?, remember, trying to change target="MyIFrame2" to something like onclick="DoSomething()" and with javascript handle the call, wouldn't change the size of my HTML file since I'd have to replace target="MyIFrame2" with onclick="DoSomething()", for this reason I mentioned a CSS before ...
Thanks in advance

T
Avatar of webwoman
webwoman

>>I'm writing a 1MB HTML (with hundreds of links with the same target) page and trying to get rid of as much text as I can.

Don't. Nobody will EVER look at it. The browser will probably time out before it completely loads. 1MB is WAY too big for one page. BREAK IT UP.

And seriously think about getting rid of the iframe.
ASKER CERTIFIED SOLUTION
Avatar of seanpowell
seanpowell
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Don't encourage them... ;-)

Unless, of course, you also tell them to add that 2.5 mb wav file as a background sound...
You could also use DOM to set the target property dynamically.

The exact script would depend on how your document is structured. For instance, if all the links to point to a particular target are in one section indicated by <div id="section1">...</div> then you can do this:

<script type="text/javascript">
 window.onload = fixTargets;

function fixTargets()
{
  var sectionOneDiv = document.getElementById("section1");
  var sectionOneLinks = sectionOneDiv.getElementsByTagName("a");

  for(var i = 0; i < sectionOneLinks.length; i++)
    sectionOneLinks[i].target = "MyIFrame1";
}
</script>

This could be generalised for many sections of a document/many targets.
Avatar of AntoniL

ASKER

Thanks Georgemarian, it did work. Thanks also to webwoman, got a tissue to wipe my tears off?
Cheers lads, see u around

T
You're welcome - and here's to unlimited bandwidth :-)