Forum Moderators: open

Message Too Old, No Replies

target="new"!?

what is the equivalent of this element that is compliant with standards?

         

boole

3:39 am on Aug 26, 2003 (gmt 0)

10+ Year Member



A question form a relative newbie:

How do you make a link open in new window in a way that is compliant to standards? target="new" is not acceptable right?

moltar

3:42 am on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It all depends which version of (X)HTML you use.

AFAIK it's ok with HTML 3 and 4.01 transitional.

Definetely bad in XHTML

Purple Martin

4:03 am on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi boole, welcome to WW.

That's a good question and one that got some good answers in this thread:
[webmasterworld.com...]

tedster

4:18 am on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, boole. First a couple references:

6.16 Frame target names

The following target names are reserved and
have special meanings.

_blank :: The user agent should load the designated
document in a new, unnamed window.

_self :: The user agent should load the document in
the same frame as the element that refers to
this target.

_parent :: The user agent should load the document
into the immediate FRAMESET parent of the current
frame. This value is equivalent to _self if the
current frame has no parent.

_top :: The user agent should load the document
into the full, original window (thus canceling
all other frames). This value is equivalent to
_self if the current frame has no parent.

W3C Reference [w3.org]

You'll notice that "new" is not on this list, so what is happening in the browser when you write target="new"?

16.3.2 Target semantics

User agents should determine the target frame
in which to load a linked resource according
to the following precedences (highest priority
to lowest):

1. If an element has its target attribute set
to a known frame, when the element is activated
(i.e., a link is followed or a form is processed),
the resource designated by the element should be
loaded into the target frame.

2. If an element does not have the target
attribute set but the BASE element does, the BASE
element's target attribute determines the frame.

3. If neither the element nor the BASE element
refers to a target, the resource designated by
the element should be loaded into the frame
containing the element.

4. If any target attribute refers to an
unknown frame F, the user agent should create a
new window and frame, assign the name F to the
frame, and load the resource designated by the
element in the new frame.

W3C Reference [w3.org]

So the browser is creating a new window that contains a single frame with the name "new". If the user then clicks on another link with target="new" it will load in that same frame. But every time a link with target="_blank" is clicked on, it will ALWAYS open a new window, and never load in an already open window.

Also note that the target attribute is not valid in either HTML 4.01 strict or XHTML 1.1 strict. However, there is a transitional DTD for HTML 4.01, and a frameset DTD for XHTML 1.1 and both of these DO allow the target attribute. However, if you are not creating a frameset website, then a strict DTD will not validate with a target attribute.

Also, see this rather thorough discussion. It may help you figure out this mess (and it is a mess, IMO):

[webmasterworld.com...]

boole

9:46 pm on Aug 26, 2003 (gmt 0)

10+ Year Member



Thanks for the feedback. You've been extreemely helpful.

It seems like a very good time to start learning HTML, since you can actually start learning it “right” :).

ronin

4:39 am on Aug 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The solution proposed by Yank is clever, but essentially it just uses javascript to insert a snippet of HTML containing the target attribute into the page code istead of hardcoding the attribute.

Okay, it dodges the validator, but if the validator could detect it, I'm pretty sure it would still say - XHTML strict does not allow markup to describe new window behaviour, only page structure, so that attribute is still invalid.

Given this, is there any way to combine CSS and Javascript to simulate target="_blank"?

That may be a daft question... is there actually any way to combine CSS and Javascript at all?