open a link in a new window...

liunx

Guest
i can't find the command at the html goodies site...<br />
<br />
what is the command so that i could open a link in a new window?<br />
<br />
thanks for your help.^^<!--content--><a href=http://www.webdeveloper.com/forum/archive/index.php/"http://www.w3.org/" onclick="window.open(this.href); return false">W3C</a><br />
<br />
or<br />
<br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"http://www.w3.org/" target="_blank">W3C</a><!--content--><a target="_blank" href=http://www.webdeveloper.com/forum/archive/index.php/""<!--content-->Note that in XHTML 1.1 and higher the target="" attribute is no longer legal.<br />
<br />
Still waiting on an answer for the alternative other than JavaScript, but I think for now I'm just going to go with that. Doesn't really matter anyway...<br />
<br />
BTW, what exactly does the return false do? I notice it has the effect of keeping the parent window at its current location but what are the technicalities? What are we returning false to? The parent window?<!--content-->You are returning false to the "onClick" event. This basically says the event has been handled, and the default handler doesn't have to do anything. If you leave it out or return true, the default action will begin. In the case of a link, the HREF action is activated.<br />
<br />
Many people code<br />
<br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"#" onclick="..."><br />
<br />
mostly for browsers that require a HREF in a link. If the "return false" is left out of the "onclick", the browser goes to a null anchor. This will make the page jump to the top, or in some cases, reload.<br />
<br />
The best of both worlds is to use a real HREF and "return false" in the "onclick". This allows browsers with javascript disabled to do something useful.<!--content-->Cool beans. Thanks.<br />
<br />
I took a class on JavaScript this semester, my exam is Thursday actually. Simple class, very very easy, and we didn't learn too many USEFUL things...some but not too many...sigh.<!--content-->Web classes, the ones taught in college at least, tend to be very light in content, and even then they skip over real world stuff. You would think a teacher would have students learn to make web pages against 4.01 recommendations at this point, but they don't. Even in a class that taught one chapter of CSS, the final exam included zero CSS code. We were told to find 20 errors in the given web pages code. I found 35 errors based on 4.01 Strict and I didn't even count taking out the code that should have been done with CSS. :-)<!--content-->Lol. That cracks me up. :D<!--content-->Originally posted by matthurne <br />
Note that in XHTML 1.1 and higher the target="" attribute is no longer legal.<br />
<br />
<br />
You are wrong.<br />
<br />
Firstly XHTML 2.0 will (very likely, it's still in draft state) have target again.<br />
<br />
Also, Neigher HTML 4.01 and XHTML 1.0 STRICT allows for target either.<!--content-->Originally posted by spufi <br />
Web classes, the ones taught in college at least, tend to be very light in content, and even then they skip over real world stuff. You would think a teacher would have students learn to make web pages against 4.01 recommendations at this point, but they don't. Even in a class that taught one chapter of CSS, the final exam included zero CSS code. We were told to find 20 errors in the given web pages code. I found 35 errors based on 4.01 Strict and I didn't even count taking out the code that should have been done with CSS. :-) <br />
<br />
LOL :D<br />
<br />
I guess most teachers don't have a first clue about what HTML really is.<!--content-->Originally posted by matthurne <br />
Note that in XHTML 1.1 and higher the target="" attribute is no longer legal.<br />
<br />
Still waiting on an answer for the alternative other than JavaScript, but I think for now I'm just going to go with that. Doesn't really matter anyway...<br />
<br />
BTW, what exactly does the return false do? I notice it has the effect of keeping the parent window at its current location but what are the technicalities? What are we returning false to? The parent window? I just want to add two things to gil's excellent post. The event handlers in JavaScript are the only things that don't follow the 'capitalize each new word in the name' convention. It's document.links[1].onclick. And, it's important to remember that 12% of users do not use JavaScript and that many of those who do use JavaScript disable pop-ups. We need the link to behave like a normal link for those people. Better that then a link that does nothing at all. For those good people, the onclick handler will be ignored and the browser will simply load the document. That's why it's important to supply the URL for the HREF attribute.<!--content-->
 
Back
Top