SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
Thread: target=new_window
-
Dec 20, 2002, 02:06 #1
- Join Date
- Oct 2002
- Location
- Still Thulcandra
- Posts
- 997
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
target=new_window
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?
-
Dec 20, 2002, 02:53 #2
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?
-
Dec 20, 2002, 03:23 #3
- Join Date
- Oct 2002
- Location
- Still Thulcandra
- Posts
- 997
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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...
-
Dec 20, 2002, 03:48 #4
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No, I was wrong, the target property is read-only
-
Dec 20, 2002, 04:17 #5
- Join Date
- Oct 2002
- Location
- Still Thulcandra
- Posts
- 997
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Which means it's impossible?
That's sad...
-
Dec 20, 2002, 04:33 #6
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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...
}
-
Dec 20, 2002, 04:35 #7
- Join Date
- Sep 2002
- Location
- Grand Rapids, MI
- Posts
- 1,168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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">
AndyFrom the English nation to a US location.
-
Dec 20, 2002, 04:40 #8
- Join Date
- Oct 2002
- Location
- Still Thulcandra
- Posts
- 997
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?
-
Dec 20, 2002, 04:41 #9
- Join Date
- Oct 2002
- Location
- Still Thulcandra
- Posts
- 997
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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?Code:<base target="_blank">
I haven't tried that... Should I just have that line in the header? Nothing more?
-
Dec 20, 2002, 04:56 #10
- Join Date
- Sep 2002
- Location
- Grand Rapids, MI
- Posts
- 1,168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
AndyFrom the English nation to a US location.
-
Dec 20, 2002, 05:01 #11
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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>
-
Dec 20, 2002, 05:37 #12
- Join Date
- Oct 2002
- Location
- Still Thulcandra
- Posts
- 997
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey guys!
I tried the simplest first... It worked! So...
Thanks to the both of you for your time, advice and patience...
-
Dec 20, 2002, 05:48 #13
- Join Date
- Sep 2002
- Location
- Grand Rapids, MI
- Posts
- 1,168
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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,
AndyFrom the English nation to a US location.
-
Dec 20, 2002, 05:48 #14
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Aha, that was all you needed? I thought you wanted to add different targets to different classes... Must read more carefully
-
Dec 20, 2002, 05:56 #15
- Join Date
- Oct 2002
- Location
- Still Thulcandra
- Posts
- 997
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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...
-
Dec 20, 2002, 05:59 #16
- Join Date
- Mar 2002
- Location
- Svíþjóð
- Posts
- 4,080
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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