Target in strict = bad validation

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

I have the following links in my Strict site.

Code: [ Select ]
<a href="http://www.google.com" target="_new">Google</a>


The document is strict. Why doesn't t validate? Below is the error message I get.

http://validator.w3.org wrote:
Image Line 27, Column 96: there is no attribute "target".

Code: [ Select ]
… href="http://www.google.com" target="_new"><b>Google</b></a><br />Google sea


You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute. If you received this error when using the <embed> element to incorporate flash media in a Web page, see the FAQ item on valid flash.


Any ideas how I can fix it?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • maxxximus
  • Beginner
  • Beginner
  • maxxximus
  • Posts: 42
  • Loc: UK

Post 3+ Months Ago

Your using a strict DTD. Your markup as you know must be free of presentational markup which should be passed to CSS but also any behavioural attributes such as opening a new window (which should be the choice of the user not the designer) should be dealt with through scripting.

You could either use transitional DTD and continue using target or manipulate the DOM with JS to achieve the same effect. Best option is just remove target and leave the user the choice to navigate away.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

OKay, I just removed the targets. Thanks anyway.

What is the javascript to do that though?
  • jameson5555
  • Bronze Robot
  • Bronze Member
  • User avatar
  • Posts: 575
  • Loc: Phoenix, AZ

Post 3+ Months Ago

Maxxximus is right that it's best to just let the user use their 'back' button to get back to your page, but sometimes it's nice to use JavaScript to open up a new custom-sized window. Here's the JavaScript code (I called everything 'store' because I was opening up an online store in a separate window):

Code: [ Select ]
//CREATES POPUP WINDOW
function showStore(linkTarget) {
    storeFront = window.open(linkTarget,"Store","directories=yes,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=800,height=500");
    storeFront.focus();
}
  1. //CREATES POPUP WINDOW
  2. function showStore(linkTarget) {
  3.     storeFront = window.open(linkTarget,"Store","directories=yes,status=yes,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,width=800,height=500");
  4.     storeFront.focus();
  5. }


and here's the code you put inside your link markup:

Code: [ Select ]
onclick="showStore('enter url here');return false"



-jameson
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

you could also use a more general version without having to have a separate javascript function:
Code: [ Select ]
<a href="MyNewWindow.php" title="Opens in a new window" onclick="window.open(this.href);return false;">My New Window</a>

The beauty of this is that you can just paste the onclick into any link and it will work without having to edit any url's.

You may notice that there is a "return false" at the end of the onclick. The purpose of that is to prevent the link from navigating the main window to the new page, since we are opening it in a new window.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

So, this script, when posted into one URL, will effect all URLs?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

No Bogey, only the ones that have the onclick event attached.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

Thanks joebert

Quote:
The beauty of this is that you can just paste the onclick into any link and it will work without having to edit any url's.


Got me a little confused.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

Sorry, I should have been a little clearer. What I meant is you can add that to any link AS IS, and it will make that link open in a new window.
In fact, if you have an editor with a halfway decent search and replace, you can can just:
search: target="_blank"
replace: onclick="window.open(this.href);return false;"

and fix non compliant pages in one go (instead of having to manually replace them one by one)
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8411
  • Loc: USA

Post 3+ Months Ago

ok. Thanks ScienceOfSpock.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 43 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.