XHTML 1.0 strict does not allow the target attribute in 'a herf'.
How can I open a page in a new window when a link is clicked, without using javascript ?
thanks.
xHTML New window without javascript
- Zarggg
- Posts: 203
- Joined: June 20th, 2003, 11:09 am
- Contact:
The <code>target</code> attribute has been excluded from the Strict doctypes as of HTML 4. You must use either Transitional doctypes or Javascript. Sorry.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
-
- Posts: 2914
- Joined: February 8th, 2003, 2:38 am
- Location: San Diego, US
- Contact:
- Zarggg
- Posts: 203
- Joined: June 20th, 2003, 11:09 am
- Contact:
- shadytrees
- Moderator
- Posts: 11743
- Joined: November 30th, 2002, 6:41 am
- Zarggg
- Posts: 203
- Joined: June 20th, 2003, 11:09 am
- Contact:
In theory, yes. However, many sites used to be made this way. I never do it, myself *shrug* All my links are plain old <.a href="link" title="title">..<./a>
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
-
- Posts: 268
- Joined: January 12th, 2003, 12:47 pm
hao2lian wrote:Isn't opening an unrequested window bad code design?
Zarggg wrote:In theory, yes. However, many sites used to be made this way. I never do it, myself *shrug* All my links are plain old <.a href="link" title="title">..<./a> :P
In my situation. It is a shopping site. By clicking on the "buy" button, the shopping cart (new window) will open, while the original window will remain the same so that the user can keep shopping other items.
I don't want to use JS for essential operation. In this case, it JS is disabled, the user won't be able to shop at all.
Don't know why xhtml strict not include the target attribut. I think it is needed in some situations.
Being xhtml 1.0 strict is quiet important for me, so i don't want to use transitional.
Really no way to go around this , without JS ? Hmmmm..!!??
- Orbite
- Posts: 3757
- Joined: November 4th, 2002, 8:23 pm
- Contact:
Re: xHTML New window without javascript
mikecop wrote:XHTML 1.0 strict does not allow the target attribute in 'a herf'.
How can I open a page in a new window when a link is clicked, without using javascript ?
thanks.
One (very bad) way to do it is
Code: Select all
<a href="http://www.whatever.com" onclick="this.target='_blank';">
One (bad) way to do this in javascript
Code: Select all
<a href="http://www.whatever.com" onclick="window.open('http://www.whatever.com','_blank'); return false;">
One (a bit better) solution is describe here : http://www.sitepoint.com/article/1041/1
Furtunately XHTML is XML, therefore you can create your own DTD.
It can be done easily with XHTML 1.1, thanks to modularisation :
Here's the dtd:
Code: Select all
<!-- ............................................................... -->
<!-- XHTML 1.1 plus Target 1.0 DTD ................................ -->
<!-- File: xhtml11-target.dtd
This is a driver file for XHTML 1.1 with the addition of the
'target' attribute (taken from the XHTML Target 1.0 module). It
is identified by the public and system identifiers:
PUBLIC "-//dmh.org.uk//DTD XHTML 1.1 plus Target 1.0//EN"
SYSTEM "http://www.dmh.org.uk/dtd/xhtml/xhtml11-target.dtd"
The system identifier may be modified appropriately, e.g. to a
location on your local machine.
A suitable DOCTYPE declaration would be:
<!DOCTYPE html
PUBLIC "-//yourname.com//DTD XHTML 1.1 plus Target 1.0//EN"
"http://yourname.com/dtd/xhtml/xhtml11-target.dtd">
Author: Dave H <dmh@dmh.org.uk>
-->
<!ENTITY % XHTML.version
"-//yourname.com//DTD XHTML 1.1 plus Target 1.0//EN" >
<!ENTITY % xhtml11.mod
PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
%xhtml11.mod;
<!ENTITY % xhtml-target.mod
PUBLIC "-//W3C//ELEMENTS XHTML Target 1.0//EN"
"http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-target-1.mod" >
%xhtml-target.mod;
<!-- End of XHTML 1.1 plus Target 1.0 DTD ......................... -->
<!-- ............................................................... -->
Place the new dtd in a directory called "dtd" off the root of your site. Your DOCTYPE would then become:
Code: Select all
<!DOCTYPE html PUBLIC "-//yourname.com//dtd xhtml 1.1 plus target 1.0//EN" "http://yourname.com/dtd/xhtml11-target.dtd">
A demo page: http://golem.ph.utexas.edu/~distler/blo ... ldman.html
<a href="http://www.catb.org/~esr/faqs/smart-questions.html">How To Ask Questions The Smart Way</a>!
Website viewing, HTML, CSS, Javascript bugs? -> <a href="http://diveintomark.org/archives/2003/05/05/why_we_wont_help_you">Help yourself</a>
Website viewing, HTML, CSS, Javascript bugs? -> <a href="http://diveintomark.org/archives/2003/05/05/why_we_wont_help_you">Help yourself</a>
- jrobbio
- Posts: 713
- Joined: June 28th, 2003, 12:40 pm
- Location: Loughborough, England
- Contact:
This is from http://www.w3.org/MarkUp/html40-updates ... 218-errata
The "href" attribute for the BASE element should not be marked as deprecated. The DTD and prose correctly indicated that it is not deprecated.
The "target" attribute should not be marked as deprecated. Though not deprecated, it is not defined in the Strict DTD either.
The "language" attribute for the SCRIPT element should be marked as deprecated and should not be in the Strict DTD.
Official Win32 BitTorrent 0.7: here
BT Tracker - Get the latest Fire/Thunderbird builds
BT Tracker - Get the latest Fire/Thunderbird builds