XHTML 1,0 and opening links in new browswers windows

  • CStrauss
  • Graduate
  • Graduate
  • User avatar
  • Posts: 122
  • Loc: St. Louis MO. USA

Post 3+ Months Ago

Any one know a work around for allowing a new window to be open up in new window when you click a link.

This is the only validation error I'm getting cause it says target _blank is not valid in xhtml 1.0 strict. It's not really a big deal, but when its the only error on your page lol its kinda of eats at you.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Validation isn't everything.

Javascript is an alternative. There's no mechanism (to my knowledge) in the XHTML Strict doctype that allows for the same functionality.
  • Zwirko
  • Guru
  • Guru
  • User avatar
  • Posts: 1417
  • Loc: 55° N, 3° W

Post 3+ Months Ago

I used this for a while, tucked away in a javascript file that I was already loading into each page:

Code: [ Select ]
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;
  1. function externalLinks() {
  2.  if (!document.getElementsByTagName) return;
  3.  var anchors = document.getElementsByTagName("a");
  4.  for (var i=0; i<anchors.length; i++) {
  5.    var anchor = anchors[i];
  6.    if (anchor.getAttribute("href") &&
  7.        anchor.getAttribute("rel") == "external")
  8.      anchor.target = "_blank";
  9.  }
  10. }
  11. window.onload = externalLinks;


A link would have the following format:
<a href="some-page.htm" rel="external">link text</a> ... the script notices the "rel" attribute and opens the link in a new window. I've also seen some scarily large versions of more or less the same code doing the same thing.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Use transitional instead of strict.

Code: [ Select ]
<!ELEMENT a %a.content;>
<!ATTLIST a
%attrs;
%focus;
charset     %Charset;     #IMPLIED
type      %ContentType; #IMPLIED
name      NMTOKEN      #IMPLIED
href      %URI;         #IMPLIED
hreflang %LanguageCode; #IMPLIED
rel         %LinkTypes; #IMPLIED
rev         %LinkTypes; #IMPLIED
shape      %Shape;      "rect"
coords     %Coords;      #IMPLIED
target     %FrameTarget; #IMPLIED
>
  1. <!ELEMENT a %a.content;>
  2. <!ATTLIST a
  3. %attrs;
  4. %focus;
  5. charset     %Charset;     #IMPLIED
  6. type      %ContentType; #IMPLIED
  7. name      NMTOKEN      #IMPLIED
  8. href      %URI;         #IMPLIED
  9. hreflang %LanguageCode; #IMPLIED
  10. rel         %LinkTypes; #IMPLIED
  11. rev         %LinkTypes; #IMPLIED
  12. shape      %Shape;      "rect"
  13. coords     %Coords;      #IMPLIED
  14. target     %FrameTarget; #IMPLIED
  15. >

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 71 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.