homepage Welcome to WebmasterWorld Guest from 50.17.107.233
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Target = Blank replacement
Anyone have a solution?
gtatler




msg:599123
 8:39 pm on Oct 7, 2005 (gmt 0)

Using target="_blank" in an html page will mean that it will not validate using W3C.

I need this so that I can refer visitors to linked external sites, without my own site being over-written (so to speak)

As I am new to web design, I was wondering if anyone has a satisfactory alternative which WILL validate.

Any help would be greatly appreciated.

By the way I am using :-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

 

mwandaw




msg:599124
 9:32 pm on Oct 7, 2005 (gmt 0)

Here's a solution that will validate as XHTML Strict:

<a href="http://yahoo.com" onclick="window.open(this.href); return false;">Go to Yahoo!</a>

Best wishes,

Mike

Robin_reala




msg:599125
 10:38 pm on Oct 7, 2005 (gmt 0)

This isn't an answer to your question but I've very sceptical about claims that people expect the originating site to stay in the background. Popups annoy me regardless and I really don't think there's any 'marketing' benefit to opening external sites in a new window.

tedster




msg:599126
 11:04 pm on Oct 7, 2005 (gmt 0)

I usually hold the same opinion as you expressed, Robin. The only time I see a value is when a target audience for a site contains many, many newbies. I am usually unhappy when a site opens links in a new window -- I know how browser work and search engines and can find my way back if I want to. But there can be a value for visitors (like my mother) who are not yet very adept with technology.

Robin_reala




msg:599127
 11:13 pm on Oct 7, 2005 (gmt 0)

I've heard this argument before Tedster. Yet I still find it difficult to understand how a user can be competent enough at using a PC to understand the concept of multiple windows and their relevance to each other, yet not be able to use a back button...

innocbystr




msg:599128
 1:43 am on Oct 8, 2005 (gmt 0)

I use target="_blank" and have no problems with it validating while using:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhmtl1/DTD/xhmtl1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

There's a slight difference, don't know if that's causing your problem or not.

gtatler




msg:599129
 9:27 am on Oct 8, 2005 (gmt 0)

Thanks innocbystr.

That seems to sort it out OK.

tedster




msg:599130
 3:54 pm on Oct 8, 2005 (gmt 0)

There's a slight difference...

Yes, there is a real difference between any two DTDs, in this case transitional xhtml 1.0 and xthml 1.1. Among other things, 1.0 transitional accommodates some html "legacy" code, such as target="_blank". Even xhtml 1.0 strict will not, and in fact html 4.01 strict also will not.

ronin




msg:599131
 11:02 am on Oct 10, 2005 (gmt 0)

gtatler> As a general rule I tend to avoid using hacks as much as possible.

But I do find I want to use target="_blank" on my site occasionally and I also want to validate my pages to the xhtml 1.0 Strict standard.

So the hack I use is this:

1) Replace all instances of target="_blank" with rel="external" (or whatever you prefer)

2) Insert this javascript in the page header:


function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;

Why does this validate when target="_blank" doesn't?

Because the target attribute is still an official part of the DOM, even if it isn't part of the xhtml strict spec.

So you can use javascript to tell the browser to apply specific target behaviours to anchor tags which contain rel="external" and the document will validate.

MatthewHSE




msg:599132
 11:21 pm on Oct 10, 2005 (gmt 0)

Is complete validation an important issue for this site? I always considered validation as a sort of guideline. By knowing which errors I'm willing to accept (and target="_blank" is one of them), the validator can still provide useful feedback even though I know from the start that the page won't actually validate.

I've looked into replacements for target="_blank", but so far I haven't found anything that really is very convincing to me. Targets are pretty well understood by modern and legacy browsers. All of the javascript alternatives seem to have cross-browser or popup-blocker issues. So, I'm willing to allow a few validation errors in exchange for the added functionality on the occasions that I need it.

My perspective on opening new browser windows with links is that any techie will hate it, but they'll also be the ones to know how to avoid allowing me to do it. For instance, I've customized Firefox so that target="_blank" links are absolutely no different than regular links. I imagine many others here have done about the same thing.

However, for other visitors, a new window under some circumstances is a definite plus. I've had many intelligent people, who know how to use their PC's quite well, object to opening new browser windows manually because they thought they'd lose their current page. These same people don't mind a link opening in a new window - "the website knows what it's doing." So I go ahead with target="_blank" whenever it seems to make sense, and my visitors seem to appreciate it.

mwandaw




msg:599133
 2:26 am on Oct 11, 2005 (gmt 0)

I agree with MatthewHSE's philosophy. I know that many technically sophisticated website users do not like new windows. They also know how to open a new window or how to prevent a new window whenever they want.

The other 99% of the Internet population appreciates a new window *under the right circumstances.* In addition, website owners (the ones who pay my bills) can be adamant about not "losing" a visitor when that visitor clicks on a link that leads to another website. I'm no fan of new windows, but there is a time and place for them.

"Vladdy" on another forum mentioned that XHTML Strict is meant to be usable on the widest variety of viewing devices, some of which do not have a window environment. For that reason, if a new window is needed, perhaps the XHTML Strict DTD should not be used. Use a transitional DTD instead. That way at least you've given non-window devices fair warning.

grandpa




msg:599134
 2:49 am on Oct 11, 2005 (gmt 0)

I used the _blank target on one page for a while, and recently stopped doing that in favor of integrating the page with the rest of the site.

However, one thing that I did in the new window, that I have not seen mentioned, is to provide a "Close this Window" link. To me that would give the page a "you're here for a special reason" feel. And when the page was closed, you usually went back to the original page.

larryhatch




msg:599135
 4:34 am on Oct 11, 2005 (gmt 0)

One thing always confused me. How do you get from target="blank", to "open in a new window"?
Suppose I put sky="blue" instead of target="blank"?
Will that make the browser beep or do something else unexpected?

My real questions are about this:
<a href="http://yahoo.com" onclick="window.open(this.href); return false;">Go to Yahoo!</a>

1) HOW does this differ in effect, from target="blank"?

2) I can see its calling to open a window for the href, namely the yahoo URL.
What's with the return false;? What does that do exactly?
Suppose I put return true; instead?

Sorry for the dumb questions. -Larry

Robin_reala




msg:599136
 6:23 am on Oct 11, 2005 (gmt 0)

It's target="_blank" for historic reasons - the target atribute was designed to let you target specific frames in a frameset. As well as being able to point a link as a specified frame there were also extra built in values like _parent and _blank which start with an underscore. Why 'blank' per se, I don't know.

ASs for the return false, that tells the browser not to follow it's default action (in this case following the href). That way users with JS enabled get the popup and users with it turned off just follow the link as per normal.

larryhatch




msg:599137
 10:32 am on Oct 11, 2005 (gmt 0)

Thanks Robin:

Gotcha on the target="blank". As for
<a href="http://yahoo.com" onclick="window.open(this.href); return false;">Go to Yahoo!</a>,
If I see links like that, is it very likely they are playing with popups? -Larry

Robin_reala




msg:599138
 10:34 am on Oct 11, 2005 (gmt 0)

Yes. If you're blocking popups then it's probably failing on the window.open and falling back to the default action which is to follow the href.

innocbystr




msg:599139
 2:28 pm on Oct 11, 2005 (gmt 0)

Hope this isn't a silly question, but is target="new" better or different than target="_blank"?

Thanks,
Blair

ronin




msg:599140
 4:02 pm on Oct 11, 2005 (gmt 0)

Someone will correct me if I'm mistaken, but as far as I'm aware target="new" is the same as target="blue", target="shoe" and target="moo".

All it does is open a new window and name that window "new", "blue", "shoe" or "moo".

If you then have another link which directs to the same target, it will open in the window that has the name of that target.

By contrast, target="_blank" will open a new, individual window every time.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved