Forum Moderators: not2easy

Message Too Old, No Replies

target_blank

target_blank

         

newseed

5:20 pm on Sep 10, 2005 (gmt 0)

10+ Year Member



I can't figure out how to apply this code - target="_blank" - to CSS?

<a class="menu-right" target="_blank" href="http://www.example.com/">Example</a>

The key here is that I want to have this link open up to a new browser.

[edited by: createErrorMsg at 5:49 pm (utc) on Sep. 10, 2005]
[edit reason] examplified url [/edit]

encyclo

5:37 pm on Sep 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't -
target="_blank"
is browser behaviour (controlled by either HTML or Javascript), whereas CSS (Cascading Style Sheets) is for styling.

newseed

5:45 pm on Sep 10, 2005 (gmt 0)

10+ Year Member



Then how can I overcome the W3C.org failed validation for this code using the HTML 4.01 Strict doc type?

benihana

5:51 pm on Sep 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



target=blank isnt part of html4 strict :(

try a transitional or loose doctype - this isnt a css issue.

cheers

createErrorMsg

5:56 pm on Sep 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't. The "target" attribute has been deprecated and will not validate to the Strict doctype. It will validate to the HTML 4.01 Transitional Doctype, however, so that's probably your best bet...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

cEM

Too slow. ;)

newseed

6:01 pm on Sep 10, 2005 (gmt 0)

10+ Year Member



I know it works fine using the Loose doc type but is there a work around that allows you to open a new window using Strict doc type?

createErrorMsg

6:09 pm on Sep 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not with CSS. Javascript can do it using the
window.open()
method.

<a href="javascript:window.open(myURL.htm);">Link Text</a>

cEM

encyclo

6:22 pm on Sep 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you need
target="blank"
, then you shold use HTML 4.01 Transitional, where it is valid. Otherwise, you are either jumping through hoops unneccessarily to trick the validator into thinking your page is valid (which is totally pointless) or you are sacrificing a desired functionality just to adhere to a particular HTML specification (which is equally pointless).

There is no disadvantage in going for a transitional doctype, and no reason not to if you need to.

newseed

6:24 pm on Sep 10, 2005 (gmt 0)

10+ Year Member



<a class="menu-right" href="javascript:window.open(http://www.example.com);">Example</a>

That didn't work but of course I probably made a mistake somewhere. Also, will it work for those that have java turned off. If not, then I best go back to Loose.

The reason I am using Strict is that evently I want to transform over the XHTML. When I do, will XHTML allow such practice or will a javascript be needed?

If moderator wish, he/she can move the topic over to the appropiate forum.

[edited by: createErrorMsg at 6:27 pm (utc) on Sep. 10, 2005]
[edit reason] examplified url [/edit]

encyclo

6:29 pm on Sep 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



XHTML 1.0 Transitional allows
target="_blank"
also, so you have no problems there. And anyway, the worst possible scenario with a user agent which suddenly decided to stop supporting target would be that the page would open in the same window - which is hardly a catastrophe.

Using Javascript as you have indicated would not function with Javascript disabled, so it would be a bad idea.

createErrorMsg

6:33 pm on Sep 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That didn't work

My mistake. You have to put the url in single quotes...

<a href="javascript:window.open('myURL.htm');">Link Text</a>

Using Javascript as you have indicated would not function with Javascript disabled, so it would be a bad idea.

Agreed. Was just presenting it as an option given newseeds desire to stick with the Strict doctype. If a Strict doctype and validation are requirements, JS is the only way to go. But with JS disabled the link will not function at all. I, like encyclo, would not recommend this option, but it's good to be aware that it exists.

Listen to encyclo, he really knows what he's talking about here...which doctype you use is not as important as following the rules of whichever doctype you choose. It's far better to identify your coding needs and select the appropriate doctype, than it is to sacrifice functionality in the name of using the "right" doctype.

cEM

newseed

6:47 pm on Sep 10, 2005 (gmt 0)

10+ Year Member



Thanks all. I have come to use Transitional Loose in this case.

It's good to know that the target"_blank" will work with XHTML transitional.

Your help was much appreciated!

You can have the rest of the weekend off now! :)