Hi,
To place a target=new_window in the <a> tags will open a new window. (At least in IE, haven't bothered to try in the other browsers, since this is a page I'm going to use locally)
But how can I put the equivalent in the css?
| SitePoint Sponsor |




Hi,
To place a target=new_window in the <a> tags will open a new window. (At least in IE, haven't bothered to try in the other browsers, since this is a page I'm going to use locally)
But how can I put the equivalent in the css?





You mean target=_blank ?
Use CSS for target attributes? I don't think target is a style property...
Or maybe you could use javascript to assign values to the target property of all links, depending on their style class?




target=_blank would be just as well... It's just that I've used new_window before, and it worked well...
Do you know how I could use js to assign value to classes? I haven't the slightest idea...





No, I was wrong, the target property is read-only![]()




Which means it's impossible?
That's sad...![]()





Nothing is impossible
You can loop through all <a> tags, get the class name, the outer html (IE only, but that's no problem since it's a local file), and then change the value of outer html for each link, depending on the class name...
Something like:
var links = document.getElementsByTagName("a");
for(var i = 0; i < links.length; i++)
{
var link = links[i];
var cls = link.className;
var htm = link.outerHTML;
//... some string.replace trick here...
}





I think - although I may be wrong - that if you specify a target that doesn't exist, then IE assumes that you mean a new window with that name, which would explain why new_window works for you.
As for the target thing, it's not the way that you wanted to do it, and if you're aiming at several targets from the same page then it'll be no help at all, but have you tried including the following in the header?Code:<base target="_blank">
Andy
From the English nation to a US location.




Hi, I'm sorry for being a little dense here, but I'll try to understand as best I can...Originally posted by jofa
Nothing is impossible
You can loop through all <a> tags, get the class name, the outer html (IE only, but that's no problem since it's a local file), and then change the value of outer html for each link, depending on the class name...
Something like:
var links = document.getElementsByTagName("a");
for(var i = 0; i < links.length; i++)
{
var link = links[i];
var cls = link.className;
var htm = link.outerHTML;
//... some string.replace trick here...
}
First line is ok... links becomes getelementsetcetera for the <a>tag
Second line... Hmmm... What's the "i" all about?
I've never heard of outerHTML before... And neither am I completely sure what the string.replace is...
Do you have the time/strength/patience to explain a little further?




Hi,Originally posted by awestmoreland
I think - although I may be wrong - that if you specify a target that doesn't exist, then IE assumes that you mean a new window with that name, which would explain why new_window works for you.
As for the target thing, it's not the way that you wanted to do it, and if you're aiming at several targets from the same page then it'll be no help at all, but have you tried including the following in the header?AndyCode:<base target="_blank">
I haven't tried that... Should I just have that line in the header? Nothing more?





I think so. I've only ever tried it in the past specifying the name of a frame as opposed to _blank, but I can't see why it shouldn't work.Originally posted by X Q mano
I haven't tried that... Should I just have that line in the header? Nothing more?
It just means that all links are opened in a new window unless you specify differently on the specific link.
Andy
From the English nation to a US location.





The i is simply the index you use when you loop through the array of <a> tags returned from getElem...
outerHTML is like innerHTML, but outer (oh, yeah, great explanation)
If <p>Text</p> is the tag, then innerHTML is == Text, and outerHTML is == <p>Text</p>
Quick and dirty example:
Code:<html> <head> <script type="text/javascript"> function assignTargets() { var links = document.getElementsByTagName("A"); for(var i = 0; i < links.length; i++) { var link = links[i]; var cls = link.className; var htm = link.outerHTML; if(cls == "Cls1") { target = "_blank"; } else if(cls == "Cls2") { target = "_self"; } htm = htm.replace("<A", "<A target=" + target); link.outerHTML = htm; } } </script> </head> <body onload="assignTargets()"> <a href="javascript:alert(this.target);" class="Cls1">Link 1</a> <a href="javascript:alert(this.target);" class="Cls2">Link 2</a> <a href="javascript:alert(this.target);" class="Cls1">Link 3</a> </body> </html>




Hey guys!
I tried the simplest first... It worked! So...
Thanks to the both of you for your time, advice and patience...





Recently someone in SPF responded to one of my threads saying that as "innerHTML" wasn't standards-compliant, that I should use text instead.
Is outerHTML compliant?
Cheers,
Andy
From the English nation to a US location.





Aha, that was all you needed? I thought you wanted to add different targets to different classes... Must read more carefully![]()




Yup, that was all I needed, sorry should have been a little more specific.
But I'll remember this thread if I ever need different classes to the different links...![]()





Seems like neither of them are standard...Originally posted by awestmoreland
Is outerHTML compliant?
http://msdn.microsoft.com/workshop/a.../innerhtml.asp
http://msdn.microsoft.com/workshop/a.../outerhtml.asp
However, Mozilla supports innerHTML, but not outerHTML, maybe that's why I thought that innerHTML was standard
Bookmarks