SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    toggle between two browser tabs or windows

    Before switching to XHTML I used the following script to enable website viewers to have two windows open and toggle between them:
    Code:
    <script type="text/javascript"> 
    <!-- 
    var newWindow = null; 
    function makeNewWindow(href, preview) 
    { 
        if (newWindow && !newWindow.closed) 
            newWindow.focus(); 
        else 
            newWindow = open(href, preview); 
        return false; 
    } 
    -->
    HTML Code:
    <h3>When you click <a href="/home/<?php echo $site_address;?>" target="preview" onclick="return makeNewWindow(this.href,this.target)">here</a> you will open a new tab where you will see....</h3>
    Now target="preview" does not validate for XHTML. It brings up the error message: 'there is no attribute "target"'. Suggestions?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any special reason that you switched to XHTML?

    The target attribute is not supported in XHTML, you will have to use JavaScript to achieve this.

  3. #3
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I switched to XHTML for many reasons, but that's another story. What I'm asking for is suggestions for changing the above script so that it will validate in XHTML.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The target attribute is deprecated in HTML 4.01 Strict, in XHTML 1.0 Strict and in XHTML 1.1.

    It is allowed in HTML 4.01 Transitional and XHTML 1.0 Transitional.

    This has nothing to do with XHTML vs HTML, and everything to do with Strict vs Transitional.

    If you want to use old-school design with target, you need to use the old-school document type declaration (Transitional).
    Birnam wood is come to Dunsinane

  5. #5
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using XHTML 1.0 Strict and not Transitional. I want to replace old-school design with "target" by something that will do the same job but not create errors in XHTML 1.0 Strict.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whatever you replace it with will still be old-school, since this is an old-school concept. The reason this behaviour is deprecated in Strict DTDs is that it should be up to the user to decide where links open.

    Let me rephrase my statement: If you want to control how links are opened, you should use the Transitional doctype declaration.
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you can add an custom attribute i.e. 'mytarget' to the tag (link) with value 'preview' and then as a parameter to function makeNewWindow, instead 'this.target' to use 'this.mytarget'?

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That wouldn't exactly help in making the markup valid XHTML.
    Birnam wood is come to Dunsinane

  9. #9
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I meant to 'add an custom attribute' with javascript:
    Code JavaScript:
    linkElement.mytarget = 'preview';

  10. #10
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason this behaviour is deprecated in Strict DTDs is that it should be up to the user to decide where links open.
    That makes perfect sense to me except in this case where the user will want to see in two separate tabs or browser sessions 1) his/her own website the results of 2) his/her work in a content management system on another website. I'm trying to make it easy to set up a situation in which they can toggle back and forth between the two sites.

    linkElement.mytarget = 'preview';
    Not sure I completely understand. Would you mind putting that in the context of the rest of the script, both the JavaScript and the HTML?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  11. #11
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bosko View Post
    I meant to 'add an custom attribute' with javascript:
    Code JavaScript:
    linkElement.mytarget = 'preview';
    Sneaking in something invalid behind the validator's back doesn't make it any less invalid.

    Besides, that won't add a custom attribute to the element, only a custom property to a Node object.
    Birnam wood is come to Dunsinane

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,713
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    If you're going to stick with XHTML then you're going to have to play by XHTML.

    Because XHTML has an eye on becoming XML, the target attribute is no longer supported. You will need to rely on javascript to perform the desired action instead.

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please see post #4 above. This has nothing to do with XHTML. The target attribute is invalid in Strict DTDs (including HTML 4.01 Strict) and valid in Transitional DTDs (including XHTML 1.0 Transitional).

    It's about modern vs old-school, not about HTML vs X(HT)ML.
    Birnam wood is come to Dunsinane

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,713
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Thanks for clarifying that, I know it can be a touchy topic.

    I have been considering moving back to HTML 4.01 Strict instead of working in XHTML for some time now, and mostly because of the IE issues with XHTML feel that it's going to be a good choice.

  15. #15
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's about modern vs old-school, not about HTML vs X(HT)ML.
    Then what is a modern approach to helping my clients open two tabs or two browser sessions (in the case of IE6) that allows them to toggle back and forth between a CMS in wndow A where they make changes to their website and window B where they see the results of their work in their website.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,713
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    The task that the target attribute performs is one that is also easily achieved by javascript.
    If your clients have javascript disabled then they will just have to do it manually, otherwise you can use javascript to help them out.

  17. #17
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The task that the target attribute performs is one that is also easily achieved by javascript.
    That's what I'm looking for. Can you provide?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  18. #18
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,713
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    The onclick event is an example of a good place to use javascript.

    Code Javascript:
    <h3>When you click
        <a href="/home/<?php echo $site_address;?>" onclick="return makeNewWindow(this.href, 'preview')">here</a>
        you will open a new tab where you will see....
    </h3>

  19. #19
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. That works great and validates for XHTML 1.0 Strict.
    Paul C.
    ClickBasics
    http://www.clickbasics.com


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
  •