ralphm — 2012-03-01T06:37:51-05:00 — #1
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:
<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.
spikez — 2012-03-01T06:55:06-05:00 — #2
mmmm tarter sauce....
ralphm — 2012-03-01T06:59:54-05:00 — #3
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. :shifty:
technobear — 2012-03-01T12:23:36-05:00 — #4
More tart than what? Or were you thinking of tartar sauce? [/ot]
spikez — 2012-03-01T15:22:26-05:00 — #5
mmm tartier....... drool
technobear — 2012-03-02T12:52:44-05:00 — #6
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.
tehyoyo — 2012-03-02T20:33:42-05:00 — #7
Although it's now allowed in HTML5.
How dost one open the link in a new window now? Presumably with they power of CSS?
ralphm — 2012-03-02T21:09:19-05:00 — #8
Usually with JavaScipt these days. E.g. if you are already using jQuery onthe site, you can add something like
tehyoyo — 2012-03-02T21:41:30-05:00 — #9
I suppose I'd understand that more if I actually knew jQuery...
ralphm — 2012-03-02T22:58:50-05:00 — #10
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
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 ...
Indeed, that's the case—which is consistent with the HTML5 motto of "paving the cowpats" [typo intended :)].
tehyoyo — 2012-03-02T23:17:53-05:00 — #11
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)
ralphm — 2012-03-02T23:24:29-05:00 — #12
Argh! :headbang: 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.
ralphm — 2012-03-02T23:38:45-05:00 — #13
Just to clarify ... I did a site once that had many internal links (to other pages within the same site), such as
<a href="/contact/">contact us</a>
and lots of external links (to other sites) like
<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):
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.)
ralphm — 2012-03-03T07:05:25-05:00 — #14
The code is
... 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.)