SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast peterkp's Avatar
    Join Date
    Mar 2009
    Location
    Auckland, NZ
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    validation question

    My web page is xhtml strict.

    I have 1 error on validation. It relates to an <a> tag with the attribute: target="_blank".

    If this attribute is not allowed under strict coding, how do you open a link in a new window?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Sometimes I right-click "open link in new window/tab", but usually I "scroll wheel click".

  3. #3
    SitePoint Enthusiast peterkp's Avatar
    Join Date
    Mar 2009
    Location
    Auckland, NZ
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I was unclear in my question. I was asking about coding. How do you code that validates in html/xhtml strict so that when someone clicks on your link it will open in a new window?

  4. #4
    Design Your Site Team bronze trophy Erik J's Avatar
    Join Date
    May 2007
    Location
    Countryside, Sweden
    Posts
    3,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use javascript.
    HTML Code:
    <a href="http://www.google.com" title="Extern link" onmouseover="this.title=(this.title=='Extern link') ? 'Opens in a new window' : this.title;" onclick="window.open(this.href);return false;">Google</a> 
    Better though is to use an unobtrusive javascript, like this example.
    Happy ADD/ADHD with Asperger's

  5. #5
    SitePoint Member
    Join Date
    May 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    who really cares if that's the only error? i would just leave it unless you're trying to put one of those gay "my site is valid xhtml strict" signs on your site.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by peterkp View Post
    how do you open a link in a new window?
    see New-Window Links in a Standards-Compliant World

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I follow the same way erik has shown.

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    For links that go to web pages, I don't open new windows, I leave that to the visitors discretion. But for my links to PDF flles I use target="_blank" with the text "opens new window" next to them. Those pages I serve as XHTML Transitional. To me it's more important for the page to be valid than it is to be Strict.

    IMHO a more important question is, Are you using doctype switching to serve "application/xhtml+xml" XHTML, or are you serving "text/html" XHTML?

  9. #9
    Design Your Site Team bronze trophy Erik J's Avatar
    Join Date
    May 2007
    Location
    Countryside, Sweden
    Posts
    3,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Erik J View Post
    ...
    Better though is to use an unobtrusive javascript. <link> snip </link>
    I think this is better. Of course it should be an external script.
    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled</title>
    <meta name="generator" content="PSPad editor, www.pspad.com">
     
    <script type="text/javascript">
    function relNofollow(){
    	var links = document.getElementsByTagName('a');
    	for (var i=0; i < links.length; i++){
    		var link = links[i];
    		if (link.getAttribute('href') && link.getAttribute('rel') == 'nofollow'){
    			link.title = "Opens in a new window";
    			link.onclick = function(){
    				window.open(this.href);
    				return false;
    			}
    		}
    	}
    }
    window.onload = relNofollow;
    </script>
     
    </head><body >
     
    <h1>Open Link In a New Window Using Javascript</h1>
    <h2>Unobtrusive Javascript</h2>
    <p><a href="http://www.google.com" rel="nofollow">Google</a></p>
    <h2>Evil Inline Javascript</h2>
    <p><a onmouseover="this.title='Opens in a new window';" onclick="window.open(this.href);return false;" href="http://www.google.com">Google</a></p>
     
    </body></html>
    Happy ADD/ADHD with Asperger's

  10. #10
    SitePoint Enthusiast peterkp's Avatar
    Join Date
    Mar 2009
    Location
    Auckland, NZ
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    For links that go to web pages, I don't open new windows, I leave that to the visitors discretion. But for my links to PDF flles I use target="_blank" with the text "opens new window" next to them. Those pages I serve as XHTML Transitional. To me it's more important for the page to be valid than it is to be Strict.
    I appreciate this thoughtful answer. For instance, I'm new enough to web design that it never occurred to me to serve different pages with different doctypes. I'm learning lots.

    Quote Originally Posted by Mittineague View Post
    IMHO a more important question is, Are you using doctype switching to serve "application/xhtml+xml" XHTML, or are you serving "text/html" XHTML?
    If this is directed to me specifically, I'm not sure what you're asking.

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    From http://www.sitepoint.com/print/html-...oes-it-matter/ under "Whither XHTML"
    Despite this honeymoon, however, the latent issues of XHTML soon began to appear. The vast majority of developers using XHTML were serving it with a text/html MIME type, which meant it was parsed by browsers as regular HTML rather than XML. To an HTML parser, an XHTML self-closing element (such as <img/>) is just an element with an extraneous character (<img>&gt;). Therefore, its successful use relies on error handling—which is what makes it backwardly compatible.
    In other words, if you serve XHTML as "text/html" then you are serving HTML with errors. This can cause browsers to use quirks (or almost standards) mode rather than standards mode. Without being in standards mode, you leave it up to the browser to "fix" the mark-up "errors" as it sees fit. Not always what you might expect and unreliable. IMHO it's more important than worrying about whether to use XHTML Strict or XHTML Transitional, since when XHTML pages are served as "text/html" they're both just HTML with errors anyway.

    For my personal site I use doctype switching to serve "application/xhtml+xml" to browsers that support it, and "text/html" to browsers that don't (i.e. IE).
    This means IE users get HTML with errors, but until (or rather if) I change the code to also serve IE proper HTML instead of XHTML as well, it's OK by me. IE seems to "fix" things OK and it's not like I don't have to think about various IE CSS "features" anyway.

  12. #12
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by techsupport21 View Post
    who really cares if that's the only error? i would just leave it unless you're trying to put one of those gay "my site is valid xhtml strict" signs on your site.
    Let me make two observations here:

    1. "Gay" is not a derogatory term, it is a sexual preference. To use it as anything else insults both gay and straight people. In other words, not in this forum, please.
    2. Like a lot of designers, I value my site being valid (X)HTML. Again, this is not the forum to ridicule the idea of making a site's code valid.

  13. #13
    SitePoint Enthusiast peterkp's Avatar
    Join Date
    Mar 2009
    Location
    Auckland, NZ
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    For my personal site I use doctype switching to serve "application/xhtml+xml" to browsers that support it, and "text/html" to browsers that don't (i.e. IE).
    This means IE users get HTML with errors, but until (or rather if) I change the code to also serve IE proper HTML instead of XHTML as well, it's OK by me. IE seems to "fix" things OK and it's not like I don't have to think about various IE CSS "features" anyway.
    Here's my personal perspective:
    1. I'm an absolute beginner.
    2. I read the link article you gave, and other stuff. Some parts make sense, some way over my head. I keep reading, and slowly build up insight.
    3. I'm using xhtml for the potent reason that the author of the first book I read used xhtml.
    4. I'm aiming for xhtml strict because I like the idea of doing it right - if I can.
    5. Reading what you said in the above quote, it makes sense in theory but I have no idea what the practical implications are.

    So my questions are:

    Should I even be thinking about this at this stage of my development?
    If so, what practical changes/additions do I make to my pages?
    (The header section of one page follows - a lot of this stuff is just cut and paste at the moment)

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    	<title>
    		Peter's Guitars - Barre chords (part 1)
    	</title>
    
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<meta name="description" content="Learn how to play your first barre chord with Peter Kirkpatrick, an experienced and friendly guitar teacher based in West Auckland...." />
    	<meta name="keywords" content="Peter Kirkpatrick, guitar teacher, student, guitar lessons, Auckland, Henderson, free, resources, strumming, finger picking, chords, scales, solos" />
    
    	<link href="http://www.petersguitars.co.nz/global/resources.css" rel="stylesheet" />
    </head>

  14. #14
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,426
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    XHTML is a subset of XML so you should use the XML prolog
    Code XML:
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE html 
            	PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
    	        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
    and the correct meta
    Code XML:
    <meta http-equiv='Content-Type' content='application/xhtml+xml; charset=utf-8' />
    and the page should be served with the correct mime type header
    PHP Code:
    header("Content-Type: application/xhtml+xml; charset=utf-8"); 
    .... When the browser is standards compliant.

    The trouble is that IE doesn't do XHTML so if you don't doctype switch you have to compromise. This results in browsers showing quirks mode HTML not XHTML, strict or otherwise.

    Is it worth doing anyway? I think so, especially when starting out. By any means you certainly won't be the only one serving XHTML as HTML. And there is nothing wrong with learning best practice for writing mark-up even if it doesn't get rendered 100&#37; correctly or take full advantage of it's potential (will MathML, SVG, eg. still work?).

    As for XHTML being "right", I don't know as it's anymore "right" then HTML Strict. At times I think I may as well go back to HTML but I haven't yet since I still toy with the idea of extending it.

  15. #15
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,597
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Black Max View Post
    1. "Gay" is not a derogatory term,
    It certainly isn't when it is used with its original meaning of "happy". All it means then is the opposite of "sad". Since there was nothing of a sexual nature in the original comment using the word you'd have to assume that the word was used with the intention of its having its usual meaning of "happy" rather than a meaning applied to it in a very specialised area.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  16. #16
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    It certainly isn't when it is used with its original meaning of "happy". All it means then is the opposite of "sad". Since there was nothing of a sexual nature in the original comment using the word you'd have to assume that the word was used with the intention of its having its usual meaning of "happy" rather than a meaning applied to it in a very specialised area.
    Stephen, that usage is very, very common among my students: "Man, that cheeseburger is gay." I should take your advice and assume a more innocent connotation, though I think my original assumption is accurate...and I'm a grumpy old, well, grump.

  17. #17
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Black Max View Post
    Stephen, that usage is very, very common among my students: "Man, that cheeseburger is gay." I should take your advice and assume a more innocent connotation, though I think my original assumption is accurate...and I'm a grumpy old, well, grump.
    The use of language evolves over time, language is not a constant and how English has become the predominant language today is through many stages of evolution. Just because a word can have more than a single meaning does not make it inappropriate, in the cases above he was directing it at an inanimate object which coherently uses the common use slang representation. Simply put there’s nothing wrong with calling something "gay" in disapproval because it has nothing in common with the sexual preference except in name... not definition or context

    Other than that I would advise the OP to not open anything in a new window, by doing such you are interfering with the browsers behaviour and forcing users to be subjected to more system resource usage then required. I really see no reason why pop-up should be used for anything anymore; if someone wants a new window they can do so through their own browser.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •