Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 38
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts

    target="_" Strict Alternative

    Is there an alternative to the deprecated target="_blank" for
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    I am having problems with my validation.

    Thanks D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    There are a number of techniques available to workaround the deprecation of the target attribute.

    This SitePoint article was amongst the early ones.
    http://www.sitepoint.com/article/sta...ompliant-world

    I also have my own, more exhaustive efforts in this area.
    http://test.newplasticarts.co.uk/dom...-offsite-links


    It's likely that some will post to recommend against using new windows as opinions about their use vary.

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Its not really a new window.

    I am having problems with the <noscript> tags - even when I remove the <a> tag, the <img> tag and replace it with just text it finds a problem with that.

    Any comments appreciated.

    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by daemonkin View Post
    Its not really a new window.
    Then why suggest that the problem is target="_blank", which is used to create new windows?

    I am having problems with the <noscript> tags - even when I remove the <a> tag, the <img> tag and replace it with just text it finds a problem with that.
    None of that is likely to make more sense we can see your code.
    Post a link to the page in question.

    Fwiw, noscript elements need to use block-level elements as their direct descendants. Placing an inline element as a direct descendant is invalid under a Strict doctype.

    e.g.
    Code:
    <!-- valid -->
    <noscript>
    	<p><a href="…"><img src="…" alt="…" /></a></p>
    </noscript>
    
    <!-- invalid -->
    <noscript>
    	<a href="…"><img src="…" alt="…" /></a>
    </noscript>
    Using noscript elements adheres to the principle of 'graceful degredation'. However, if you follow the approach of 'progressive enhancement' instead, there should be no need for noscript elements.

    The principles of progressive enhancement mean starting with the non-js version and then using js to remove or replace certain parts of the markup or enhance them with js functionality.

    The SitePoint article and my own js method both show how the principle of progressive enhancement can be used to tackle the issue of links and new windows.
    Last edited by Bill Posters; 06-28-2007 at 12:57 PM.

  • #5
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    It is possible to do with Javascript, with this line added to the link

    Code:
    onclick="window.open(this.href, '_blank'); return false;"
    But I advice you not to use it, because the user has absolutely no choice whether to open or not and if he or she holds down Ctrl while pressing, it will open two windows (tabs in my case, because I use Firefox).

  • #6
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Jutlander View Post
    It is possible to do with Javascript, with this line added to the link

    Code:
    onclick="window.open(this.href, '_blank'); return false;"
    But I advice you not to use it, because the user has absolutely no choice whether to open or not and if he or she holds down Ctrl while pressing, it will open two windows (tabs in my case, because I use Firefox).
    Fwiw, if you use js to add the target, then it won't trigger the double window issue.

    e.g.
    Code:
    <a href="…" onclick="this.target='_blank';">…</a>
    I know it's not ideal as it kinda goes against the sentiment of its deprecation, but so long as using window.open triggers a second new window, …

    Fwiw, my own method, to which I linked in an earlier post provides a toggler, enabling users to choose whether external links should open in a new window or not.
    (It covers those who might like it so, but who aren't sufficiently familiar with their UA to enact it themselves.)


    Of course, in all cases, links which open in new windows should provide notice to users of that behaviour, either by text, icon or a combination of both.
    Last edited by Bill Posters; 06-28-2007 at 08:10 PM.

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    If you use target="_blank" either in the HTML or the JavaScript then you should be using a transitional doctyle as your page is no longer valid for strict. Adding invalid elements after you validate doesn't make the page valid, it just means you are validating only part of the page.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    IMO, developers shouldn't put any code in the links that open them in a new window or tab. Let the users decide for themselves.

  • #9
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by felgall View Post
    If you use target="_blank" either in the HTML or the JavaScript then you should be using a transitional doctyle as your page is no longer valid for strict. Adding invalid elements after you validate doesn't make the page valid, it just means you are validating only part of the page.
    Until the W3C stipulate to UA developers that deprecated attributes should be unaddressable/unsettable via the DOM, there's wiggle room for interpretation over just how wrong using the target attribute via js under a Strict doctype is.

    However, as mentioned, the use of the target attribute is a less-than-ideal fallback used due to the problems which arise when using the window.open method.


    (Fwiw, I shall continue to use Strict doctype regardless, because it's the only doctype which can set browsers on their absolute, best behaviour.)

  • #10
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Jutlander View Post
    IMO, developers shouldn't put any code in the links that open them in a new window or tab. Let the users decide for themselves.
    This is part of a long and often over-simplified argument.
    Suffice to say that I won't go into it now, but the end result is invariably - views differ.

  • #11
    Regular Coder Jutlander's Avatar
    Join Date
    Jun 2007
    Location
    In my own sick little world :P
    Posts
    425
    Thanks
    1
    Thanked 12 Times in 12 Posts
    I am aware of that, that's why I used the abbreviation "IMO" as the first.

  • #12
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,315
    Thanks
    29
    Thanked 279 Times in 273 Posts
    Quote Originally Posted by daemonkin View Post
    Is there an alternative to the deprecated target="_blank" for
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    I am having problems with my validation.
    Your valid alternatives are to (A) generate a pseudo‐window by use of something like an absolutely positioned div and scripting, (B) use proprietary methods such as window.open(), or (C) switch to use of the HTML or XHTML Transitional DTD so that you can use the target attribute.

    Your invalid alternatives are to (A) use the target attribute anyway or (B) use scripting to generate the target attribute. The latter method will allow you to maintain the guise of using valid code while not actually doing so. I point this out, mainly, since solution (B) is what Bill Posters and that SitePoint article would have you do. I would imagine that the main advantage (of (B)) is so that you can show others that you’ve produced “valid” code while being compelled to use a Strict DTD for whatever reason.

    I would take into careful consideration whether generating a new window is actually necessary. If it is not, I would avoid doing so.

    Quote Originally Posted by Bill Posters View Post
    Until the W3C stipulate to UA developers that deprecated attributes should be unaddressable/unsettable via the DOM, there's wiggle room for interpretation over just how wrong using the target attribute via js under a Strict doctype is.
    element.setAttribute("target", "_blank") is the same thing as <element target="_blank"/>. Thus, setting the attribute via the DOM results in an invalid document. I would imagine that an implementation of DOM3 Validation and element.allowedAttributes or element.canSetAttribute("target", value) would affirm this; it’s unfortunate that I don’t have such an implementation to demonstrate with.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #13
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Arbitrator View Post
    element.setAttribute("target", "_blank") is the same thing as <element target="_blank"/>. Thus, setting the attribute via the DOM results in an invalid document. I would imagine that an implementation of DOM3 Validation and element.allowedAttributes or element.canSetAttribute("target", value) would affirm this; it’s unfortunate that I don’t have such an implementation to demonstrate with.
    With all respect, you can go on about how using scripting to implement the invalid target attribute is bad mojo until you're blue in the face. I've already acknowledged that it's not the ideal approach. However, it's still the least problematic option available and I'll continue to use it (and endorse it, with caveats) until UAs manages to sort out a better way to deal with links which use window.open which have also been targeted at a new window/tab by the user.

    I use it knowingly, aware that it doesn't tick all the boxes, but also knowing that the validity of the computed DOM is not always the absolute be-all and end-all. As said, until such time as UA or the DOM actively and practically reflect spec DOM validity, it's there as an option.

    Truth be told, I don't see it as being that much different in principle to using conditional comments to shield the DOM from non-standard, IE-targeted markup or CSS. It's a trick, but these are the things we are sometimes required to do to achieve the results we want.
    Last edited by Bill Posters; 06-29-2007 at 09:53 AM.

  • #14
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,315
    Thanks
    29
    Thanked 279 Times in 273 Posts
    Quote Originally Posted by Bill Posters View Post
    With all respect, you can go on about how using scripting to implement the invalid target attribute is bad mojo until you're blue in the face. I've already acknowledged that it's not the ideal approach. However, it's still the least problematic option available and I'll continue to use it (and endorse it, with caveats) until UAs manages to sort out a better way to deal with links which use window.open which have also been targeted at a new window/tab by the user.
    If your basic point is, “While setting the target attribute under a Strict DTD via scripting is technically invalid, due to the poor state of current implementations, I would suggest a compromise in favor of functionality and use the attribute in such a circumstance anyway,” then I see no need to argue.

    However, my impression is that you’re implying that using the DOM to insert the attribute means that the document is valid. One of my objectives is to dispel such illusions. If one is going to set the target attribute anyway, they might as well take the easy path and just set the attribute directly, without use of the DOM. The only reasonings that I can see for the scripting‐based approach is if one wants to build extra functionality onto the attribute (e.g., as shown in your second resource) or a client (including one’s self) insists upon a Strict DTD, validity, and the ability to reliably generate new windows at the same time and one wants to also be deceptive about meeting the validity constraint.

    Quote Originally Posted by Bill Posters View Post
    Truth be told, I don't see it as being that much different in principle to using conditional comments to shield the DOM from non-standard, IE-targeted markup or CSS.
    A conditional comment is, literally, just a comment from a technical point of view. That Internet Explorer does something proprietary with it doesn’t make it less valid. It’s different because a correct implementation will see a valid document.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #15
    Regular Coder nolvorite's Avatar
    Join Date
    Dec 2006
    Posts
    176
    Thanks
    7
    Thanked 0 Times in 0 Posts
    If you want your page to be valid w/ that doctype, use javascript. period.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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