SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,165
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    I'm afraid your question is not very clear. You use target="_blank" on links, but it is very outdated and not good to use any more.

    But is is used like so:

    Code:
    <a href="#" target="_blank">Contact</a>
    You have a strict doctype, and tarter="_blank" is not allowed with that doctype, so the page won't validate.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Off Topic:


    Quote Originally Posted by ralph.m View Post
    You have a strict doctype, and tarter="_blank" is not allowed with that doctype, so the page won't validate.
    mmmm tarter sauce....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,165
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    By the way, you have a strict doctype, so target="_blank" also is not allowed with that doctype, so the page also won't validate if you use that.

  4. #4
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,143
    Mentioned
    261 Post(s)
    Tagged
    5 Thread(s)
    Off Topic:

    Quote Originally Posted by spikeZ View Post

    mmmm tarter sauce....
    More tart than what? Or were you thinking of tartar sauce?

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Off Topic:


    mmm tartier....... *drool*
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    Life is not a malfunction gold trophysilver trophybronze trophy
    TechnoBear's Avatar
    Join Date
    Jun 2011
    Location
    Argyll, Scotland
    Posts
    6,143
    Mentioned
    261 Post(s)
    Tagged
    5 Thread(s)
    Quote Originally Posted by chol7024 View Post
    Ex: you are visiting it and now you click on post title sure it will give you another page. Refer to my question is, I don't want you to leave my home page by click on this title. Meanwhile home page still appear and new page is also appearing after that.
    You mean you want the new page to appear in a new window? ralph.m gave you an example of how to do that, but he also explained that it is no longer considered good practice. It means that people can't get back to where they were using the back button, and it can be particularly difficult and annoying for those using screen readers and other assistive technologies.

    Why do you want people to keep your home page open when they're visiting another page? After all, most people can only read one page at a time.

  7. #7
    <title class="lol"> bronze trophy TehYoyo's Avatar
    Join Date
    Feb 2012
    Location
    Northeast Chicago Suburbs
    Posts
    806
    Mentioned
    18 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by TechnoBear View Post
    You mean you want the new page to appear in a new window? ralph.m gave you an example of how to do that, but he also explained that it is no longer considered good practice. It means that people can't get back to where they were using the back button, and it can be particularly difficult and annoying for those using screen readers and other assistive technologies.

    Why do you want people to keep your home page open when they're visiting another page? After all, most people can only read one page at a time.
    Although it's now allowed in HTML5.

    How dost one open the link in a new window now? Presumably with they power of CSS?

    ~TehYoyo

  8. #8
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,165
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by TehYoyo View Post
    How dost one open the link in a new window now? Presumably with they power of CSS?
    Usually with JavaScipt these days. E.g. if you are already using jQuery onthe site, you can add something like

    Code:
    $(document).ready(function(){
    	$("a[@href^='http']").attr('target','_blank');
    });

  9. #9
    <title class="lol"> bronze trophy TehYoyo's Avatar
    Join Date
    Feb 2012
    Location
    Northeast Chicago Suburbs
    Posts
    806
    Mentioned
    18 Post(s)
    Tagged
    1 Thread(s)
    I suppose I'd understand that more if I actually knew jQuery...

    Thanks Ralph.
    ~TehYoyo

  10. #10
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,165
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by TehYoyo View Post
    I suppose I'd understand that more if I actually knew jQuery...
    Yeah, I don't really understand it either. But in this case, it tells the browser to add target="_blank" to any link that includes "http" in its URL. So, for example, you could use this on a site where you wanted any link that includes "http" to open in a new window (such as an external link) but not to do so for internal site links (which might, for example, be root relative links, and thus not contain "http").

    If you just wanted all links to open in a new window, you could just use

    Code:
    $(document).ready(function(){
    	$("a").attr('target','_blank');
    });
    All the same, as has already been discussed, this kind of behavior is not recommended now anyway, as it is confusing to users and kind of ruins the functionality of the web (the back button etc.).

    If you are going to use tartet="_blank", it's a good idea to use an outdated transitional doctype, to help remind you that the site is using outdated code. Except that ...

    Quote Originally Posted by TehYoyo
    ... it's now allowed in HTML5.
    Indeed, that's the case—which is consistent with the HTML5 motto of "paving the cowpats" [typo intended ].

  11. #11
    <title class="lol"> bronze trophy TehYoyo's Avatar
    Join Date
    Feb 2012
    Location
    Northeast Chicago Suburbs
    Posts
    806
    Mentioned
    18 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ralph.m View Post
    If you are going to use tartet="_blank"
    Well, I really wouldn't recommend using that syntax either...it probably won't work.

    In all seriousness, can you use jQuery to only open some links in new windows? For instance, I imagine internal page links and links to other parts of the site would want to be same-window links.

    Also, why should we use jQuery to add attributes rather than just doing it ourself? Ease of use? (Universal w/out concious effort)

    ~TehYoyo

  12. #12
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,165
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by TehYoyo View Post
    Well, I really wouldn't recommend using that syntax either...it probably won't work.
    Argh! That's the second time I've mistyped that.

    can you use jQuery to only open some links in new windows? For instance, I imagine internal page links and links to other parts of the site would want to be same-window links.
    You can create any combination you like, but the example I first posted was just to open external links in a new window, with the idea that you don't want people to leave your site to go to a new one. (I had a client once that insisted on this, despit my objections.)

    Also, why should we use jQuery to add attributes rather than just doing it ourself? Ease of use?
    Either just to get around the validator (if you have a strict doctype) or as an easy way to reverse engineer a site so that you don't have to go around adding the attributes manually. But other than that, it is indeed pointless to use JS to do this.

  13. #13
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,165
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by chol7024 View Post
    Sorry my HTML knowledge is poor and now using HTML in Blogger. Can you share...
    Just to clarify ... I did a site once that had many internal links (to other pages within the same site), such as

    Code:
    <a href="/contact/">contact us</a>
    and lots of external links (to other sites) like

    Code:
    <a href="http://someothersite.com">bye bye</a>
    Suddenly, the client demanded that all external links open in a new window (so that people wouldn't leave his site when they clicked an external link).

    Instead of going through the whole site and adding hundreds of target="_blank" attributes to all those external links, I just added this simple code to the <head> of each page (which I did just once, because most of the <head> content was fed to each page via a single include file):

    Code:
    http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
    $(document).ready(function(){
    	$("a[@href^='http']").attr('target','_blank');
    });
    </script>
    That's a much simpler solution, even though it means the user will have do download the entire jQuery library! (In the case of the site, that was already being used for other purposes anyway, so I've just added that first line above to show how you could do this if you weren't already using jQuery on the site.)

  14. #14
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,165
    Mentioned
    453 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by chol7024 View Post
    Just tell me what is the code
    The code is

    Code:
    http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
    $(document).ready(function(){
    	$("a[@href^='http']").attr('target','_blank');
    });
    </script>
    ... and where to put ...
    Put in <head>.

    (I don't know how Blogger works, though, so am not sure how much control you have over this stuff.)


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
  •