target="_blank"... but better ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Romain

    target="_blank"... but better ?

    Hi,

    I've used an excellent way to make target="_blank" links that still
    validate while using HTML 4.01 Transitional doctypes in the past.

    I learned the trick from : http://www.sitepoint.com/article/1041

    Basically, instead of typing :
    <a href="yourlink. html" target="_blank" alt="">The link</a>

    You type :
    <a href="yourlink. html" class="external " alt="">The link</a>

    And it's the same due to this little piece of javascript :

    /* Evite de mettre des target="_blank" */
    function externalLinks() {
    if (!document.getE lementsByTagNam e) return;
    var anchors = document.getEle mentsByTagName( "a");
    for (var i=0; i<anchors.lengt h; i++) {
    var anchor = anchors[i];
    if (anchor.getAttr ibute("href") &&
    anchor.getAttri bute("class") == "external")
    anchor.target = "_blank";
    }
    }
    window.onload = externalLinks;

    Now, eventhough this perfectly works, I wish I could do a little
    something more (with your help).

    What I would like to archieve would be the following :

    When typing :
    <a href="yourlink. html" class="external " alt="">The link</a>

    I would like to obtain :
    <a href="yourlink. html" class="external " alt="">The link</a> (<a
    href="yourlink. html" class="external 2" alt="">new window</a>)

    So what I would like is the ability to :
    1°) Add (<a href="yourlink. html" class="external 2" alt="">new
    window</a>) after my original link
    2°) indicate by this mean that the link could be followed either on the
    same page or another one.
    3°) have class="external " that opens nothing and class="external 2" that
    opens a new window automaticaly.

    What I don't know is :
    1°) Is it feasible using only javascript ?
    2°) Is it possible only by specifiing class="external " in the original
    link (and having javascript doing the subsequent coding) ?
    3°) Is someone able to come up with a solution (because I truly can't)

    Hope I'll get some expert coders attention ;)

    Greetings.

    R.
  • David Dorward

    #2
    Re: target=&quot;_b lank&quot;... but better ?

    Romain wrote:[color=blue]
    > I've used an excellent way to make target="_blank" links that still
    > validate while using HTML 4.01 Transitional doctypes in the past.[/color]

    Oh dear. Opening new windows is not a good idea:
    สล็อตเว็บตรง Abacusjaspers.com ระบบแท้ API เวอร์ชั่นล่าสุด เล่นง่าย ฝากถอนทรูวอเลท เล่นได้ทุกเกม ไม่ต้องโยกเงิน เว็บใหม่ ที่คุณห้ามพลาด !

    [color=blue]
    > I learned the trick from : http://www.sitepoint.com/article/1041[/color]

    That isn't excellent, it's plain wrong and the document is still invalid.
    See:



    --
    David Dorward http://david.us-lot.org/

    Comment

    • splish

      #3
      Re: target=&quot;_b lank&quot;... but better ?

      David
      I've gotta say "Opening a new window" IS a good idea if it's required.
      Don't forget, the bulk of surfing folk are operating a system called....
      wait for it.... "Windows", hence the acceptance of windows.
      Chillout pal. Write about something important.

      Splishman.


      "David Dorward" <dorward@yahoo. com> wrote in message
      news:bfr49o$fri $2$8300dec7@new s.demon.co.uk.. .[color=blue]
      > Romain wrote:[color=green]
      > > I've used an excellent way to make target="_blank" links that still
      > > validate while using HTML 4.01 Transitional doctypes in the past.[/color]
      >
      > Oh dear. Opening new windows is not a good idea:
      > http://diveintoaccessibility.org/day...w_windows.html
      >[color=green]
      > > I learned the trick from : http://www.sitepoint.com/article/1041[/color]
      >
      > That isn't excellent, it's plain wrong and the document is still invalid.
      > See:
      >[/color]
      http://groups.google.com/groups?selm...&output=gplain[color=blue]
      >
      >
      > --
      > David Dorward http://david.us-lot.org/[/color]


      Comment

      • Lee

        #4
        Re: target=&quot;_b lank&quot;... but better ?

        "splish" said:[color=blue]
        >
        >David
        >I've gotta say "Opening a new window" IS a good idea if it's required.
        >Don't forget, the bulk of surfing folk are operating a system called....
        >wait for it.... "Windows", hence the acceptance of windows.[/color]

        The point is that you must develop your pages to be usable by
        everybody, not just "the bulk". If you've got a commercial
        web page, you may be in violation of the law if some features
        aren't accessible by even a few people.

        Comment

        • Lee

          #5
          Re: target=&quot;_b lank&quot;... but better ?

          Romain said:[color=blue]
          >
          >Hi,
          >
          >In article <bfr49o$fri$2$8 300dec7@news.de mon.co.uk>,
          > David Dorward <dorward@yahoo. com> wrote:
          >[color=green]
          >> Romain wrote:[color=darkred]
          >> > I've used an excellent way to make target="_blank" links that still
          >> > validate while using HTML 4.01 Transitional doctypes in the past.[/color]
          >>
          >> Oh dear. Opening new windows is not a good idea:
          >> http://diveintoaccessibility.org/day...w_windows.html[/color]
          >
          >Well at least it's the way I WANT IT... Maybe it's clearer now.
          >[color=green][color=darkred]
          >> > I learned the trick from : http://www.sitepoint.com/article/1041[/color]
          >>
          >> That isn't excellent, it's plain wrong and the document is still invalid.
          >> See:
          >>http://groups.google.com/groups?selm...0%40news.demon.
          >> co.uk&output=gp lain[/color]
          >
          >
          >Ok, it's invalid. No argue about that. But still. I wasn't seeking for
          >your approval, rather for some enlighting pieces of code.[/color]

          If you're not concerned with validity, why not simply use target="_blank"
          when you want a new window and target="_self" (or "_top") when you don't?
          Then it will even work for people who have disabled JavaScript.

          I know that isn't the answer that you want to hear, but every now and
          then somebody will actually seem to appreciate being told that the way
          they're asking to do something isn't reasonable.

          Comment

          • Douglas Crockford

            #6
            Re: target=&quot;_b lank&quot;... but better ?

            > >I've gotta say "Opening a new window" IS a good idea if it's required.[color=blue][color=green]
            > >Don't forget, the bulk of surfing folk are operating a system called....
            > >wait for it.... "Windows", hence the acceptance of windows.[/color][/color]
            [color=blue]
            > The point is that you must develop your pages to be usable by
            > everybody, not just "the bulk". If you've got a commercial
            > web page, you may be in violation of the law if some features
            > aren't accessible by even a few people.[/color]

            Web standards do not have the force of law. That's just nutty.

            Comment

            • Jim Ley

              #7
              Re: target=&quot;_b lank&quot;... but better ?

              On Fri, 25 Jul 2003 13:49:04 -0700, "Douglas Crockford"
              <nospam@laserli nk.net> wrote:
              [color=blue][color=green][color=darkred]
              >> >I've gotta say "Opening a new window" IS a good idea if it's required.
              >> >Don't forget, the bulk of surfing folk are operating a system called....
              >> >wait for it.... "Windows", hence the acceptance of windows.[/color][/color]
              >[color=green]
              >> The point is that you must develop your pages to be usable by
              >> everybody, not just "the bulk". If you've got a commercial
              >> web page, you may be in violation of the law if some features
              >> aren't accessible by even a few people.[/color]
              >
              >Web standards do not have the force of law. That's just nutty.[/color]

              However a law is free to require adherance to a web standard as part
              of its application, such as current Accessibility laws which simply
              cite W3's WCAG guidelines as being accessible (and it does require
              validity).

              Jim.
              --
              comp.lang.javas cript FAQ - http://jibbering.com/faq/

              Comment

              • Jim Ley

                #8
                Re: target=&quot;_b lank&quot;... but better ?

                On Sat, 26 Jul 2003 02:02:44 +1000, "splish" <cms@congosyste ms.com>
                wrote:
                [color=blue]
                >David
                >I've gotta say "Opening a new window" IS a good idea if it's required.
                >Don't forget, the bulk of surfing folk are operating a system called....
                >wait for it.... "Windows", hence the acceptance of windows.
                >Chillout pal. Write about something important.[/color]

                Yet the largest ISP in the world specifically markets on the fact that
                it has a popup-stopper - not that it's fast, not that it's reliable,
                but that it stops windows opening - are you sure they're accepted and
                that ISP's marketing is just flawed?

                Jim.
                --
                comp.lang.javas cript FAQ - http://jibbering.com/faq/

                Comment

                • DU

                  #9
                  Re: target=&quot;_b lank&quot;... but better ?

                  Lee wrote:
                  [color=blue]
                  > "splish" said:
                  >[color=green]
                  >>David
                  >>I've gotta say "Opening a new window" IS a good idea if it's required.
                  >>Don't forget, the bulk of surfing folk are operating a system called....
                  >>wait for it.... "Windows", hence the acceptance of windows.[/color]
                  >
                  >
                  > The point is that you must develop your pages to be usable by
                  > everybody, not just "the bulk". If you've got a commercial
                  > web page, you may be in violation of the law if some features
                  > aren't accessible by even a few people.
                  >[/color]

                  Saying that "Opening a new window" is a bad idea is abstract, general,
                  without any grip on any specific case. 90% of all pages relying on popup
                  do not use flexible, robust cross-browser code and have no concerns
                  about accessibility and usability.
                  Nevertheless, a page using popups can be a respectable and responsible
                  webdesign decision.

                  DU
                  --
                  Javascript and Browser bugs:


                  Comment

                  • Jim Ley

                    #10
                    Re: target=&quot;_b lank&quot;... but better ?

                    On Sat, 26 Jul 2003 12:47:27 -0400, Romain <user@domain.tl d> wrote:
                    [color=blue]
                    >Oh, and by the way, I neither live in the US nor in the UK, I don't have
                    >a commercial web site, and I really don't care about ADA, DAA (american
                    >only RECOMMENDATIONS ).[/color]

                    Guessing from headers at you being in the same country as me:



                    but as you note you're not doing commercial (this would include
                    Government or charity or many other organisations, home publishing it
                    wouldn't) it matters little to you, however in discussing stuff on the
                    group, many of us do care, so it is still relevant to point stuff out.
                    [color=blue]
                    >I just want to offer a convenient (don't argue with that last personnal
                    >opinion please) way to choose between opeing a link in the same window,
                    >or in a new one, by LETTING the user do the choice.[/color]

                    That's good, and is certainly more accessible than most (there's
                    problems with what happens when you take links out of context as many
                    AT's do in your example but it's not too serious)

                    Jim.
                    --
                    comp.lang.javas cript FAQ - http://jibbering.com/faq/

                    Comment

                    • Lee

                      #11
                      Re: target=&quot;_b lank&quot;... but better ?

                      Romain said:[color=blue]
                      >
                      >In article <bfs3ev02e08@dr n.newsguy.com>,
                      > Lee <REM0VElbspamtr ap@cox.net> wrote:
                      >[color=green]
                      >> If you're not concerned with validity, why not simply use target="_blank"
                      >> when you want a new window and target="_self" (or "_top") when you don't?
                      >> Then it will even work for people who have disabled JavaScript.[/color]
                      >
                      >Simply because I want this :
                      >
                      ><a href="link.html " class="external ">the link</a>
                      >
                      >To be transformed into this :
                      >
                      ><a href="link.html " class="external ">the link</a> (<a href="link.html "
                      >target="_blank ">In a new window</a>)
                      >
                      >So that users can choose between opening a link in the same window, or
                      >not. And since all my "external" links already have the class="external "
                      >attribute that'll be VERY convenient instead of replace each and every
                      >link (above 5000).
                      >
                      >All this was clearly explained in my first thread, obviously you skipped
                      >that part.[/color]

                      I read that part. You did not cleary explain that you wanted the
                      users to be able to choose whether links were opened in the same
                      window or in a new one. I got the impression that you, as the
                      page designer, would be making that decision.
                      [color=blue]
                      >I just want to offer a convenient (don't argue with that last personnal
                      >opinion please) way to choose between opeing a link in the same window,
                      >or in a new one, by LETTING the user do the choice.[/color]

                      In that case, there is a *much* simpler way to do what you
                      want. Too bad you're an asshole, or somebody might help you.

                      Comment

                      • DU

                        #12
                        Re: target=&quot;_b lank&quot;... but better ?

                        Romain wrote:
                        [color=blue]
                        > In article <bfs3ev02e08@dr n.newsguy.com>,
                        > Lee <REM0VElbspamtr ap@cox.net> wrote:
                        >
                        >[color=green]
                        >>If you're not concerned with validity, why not simply use target="_blank"
                        >>when you want a new window and target="_self" (or "_top") when you don't?
                        >>Then it will even work for people who have disabled JavaScript.[/color]
                        >
                        >
                        > Simply because I want this :
                        >
                        > <a href="link.html " class="external ">the link</a>
                        >
                        > To be transformed into this :
                        >
                        > <a href="link.html " class="external ">the link</a> (<a href="link.html "
                        > target="_blank" >In a new window</a>)
                        >
                        > So that users can choose between opening a link in the same window, or
                        > not. And since all my "external" links already have the class="external "
                        > attribute that'll be VERY convenient instead of replace each and every
                        > link (above 5000).
                        >
                        > All this was clearly explained in my first thread, obviously you skipped
                        > that part.
                        >
                        > Oh, and by the way, I neither live in the US nor in the UK, I don't have
                        > a commercial web site, and I really don't care about ADA, DAA (american
                        > only RECOMMENDATIONS ).
                        >
                        > <troll>ONU made recommendations about controling guns, kyoto agreements,
                        > not starting a war in Irak etc. USA (& UK) didn't care. Why should I
                        > care about USA (&UK) recommendations today ?</troll>
                        >
                        > I just want to offer a convenient (don't argue with that last personnal
                        > opinion please) way to choose between opeing a link in the same window,
                        > or in a new one, by LETTING the user do the choice.
                        >
                        > And for the accessibility concerned, doing so doesn't prevent disabled
                        > people to watch my web site (although I doubt that they will ever find
                        > an interest to "read" my thoughts and "watch" my pictures).
                        >
                        >
                        > R.[/color]

                        There is something better than target="_blank" (I am assuming here that
                        your website design justifies the use of popups and meets widely known
                        accessibility and usability requirements). Just give a name to the new
                        window (say, target="Request edPopup") and then re-use the popup window.
                        I've coded requested popups before and I never ever saw the relevance of
                        creating new unnamed popup windows. Just allow the users to re-use the
                        same popup window, even if javascript is turned off. If you code
                        carefully, you can make your code robust, flexible and versatile so that
                        the user can open new unnamed popup windows (if this is what he really
                        wants and in as many new unnamed "_blank" popup windows as he wants) via
                        a right-click, open the referenced resource in a new tab or in the same
                        window... or open the reference resource in the same unique named
                        requested popup. The possibilities here are only limited by the browsers.

                        Here's a page allowing all this (use NS 7.1 or Mozilla 1.0+ to try all
                        alternatives):



                        DU
                        --
                        Javascript and Browser bugs:


                        Comment

                        • nice.guy.nige

                          #13
                          Re: target=&quot;_b lank&quot;... but better ?

                          While the city slept, Romain <user@domain.tl d> feverishly typed:
                          [color=blue]
                          > In article <bg0bcv$ic47q$1 @ID-112325.news.uni-berlin.de>,
                          > "nice.guy.n ige" <nigel_moss@dea dspam.com> wrote:
                          >[color=green]
                          >> While the city slept, Romain <user@domain.tl d> feverishly typed:[/color]
                          >[color=green][color=darkred]
                          >>> Basically, instead of typing :
                          >>> <a href="yourlink. html" target="_blank" alt="">The link</a> [...][/color]
                          >>
                          >> As an aside, there is no alt attribute for <a>, so you do not need to
                          >> declare it empty (and shouldn't really declare it at all). You can,
                          >> however use the title attribute with <a> if you wish, but it is not
                          >> mandatory.[/color]
                          >
                          > Oups, my mistake... I mean title of course...[/color]

                          <g> But as I said before, title is not a mandatory attribute in <a>, so you
                          don't need to declare an empty one if you don't want a title.

                          Cheers,
                          Nige

                          --
                          Nigel Moss.

                          Email address is not valid. nigel@nigenetDO G.org.uk. Take the dog out!
                          http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
                          "How strange the change from major to minor..."


                          Comment

                          Working...