...

View Full Version : target="new"



cdc08x
12-08-2005, 10:37 PM
I hope this is not a problem that many people before me can have asked about but...
if I do not use javascript, is there an XHTML-compliant way to make an anchor open another window? As well known, the attribute target="new" ir target="blank" is not accepted anymore by W3C standards!

badg0003
12-08-2005, 10:47 PM
You are allowed to use target="_blank", but only if you are using a Transitional or Frameset DTD. The Strict DTD will produce a validation error.

cdc08x
12-08-2005, 11:23 PM
Thank you!
I'll read more about this...

Considering my first theme, that is accessibility, do you think I'd better abandon the Strict DTD compliance or keep it and use js?

gsnedders
12-08-2005, 11:24 PM
I'd just keep it opening in the same window, let the user choose if they want it in a new window/tab.

Bill Posters
12-09-2005, 10:52 AM
I'd just keep it opening in the same window, let the user choose if they want it in a new window/tab.

It's not always the case that the user knows the browser well enough to know how to open links in a new window.

Fwiw, there's some worthwhile reading over at this AccessifyForum thread.
http://www.accessifyforum.com/viewtopic.php?t=4209

Jan
12-09-2005, 12:17 PM
I've asked the same some time ago and was pointed to this excellent post:
http://www.youngpup.net/2003/popups

If you want to open a link in a new window (which in my opinion should be avoided), simply use


<a href="http://www.yourlink.com/" onclick="window.open(this.href); return false;">Your link</a>

Works like a charm. :)

Bill Posters
12-09-2005, 12:51 PM
If you want to open a link in a new window (which in my opinion should be avoided), simply use


<a href="http://www.yourlink.com/" onclick="window.open(); return false;">Your link</a>

Works like a charm. :)
Not without a url argument in the window.open method it doesn't. ;)

I guess you meant this…

<a href="http://www.yourlink.com/" onclick="window.open(this.href); return false;">Your link</a>

…but even then, it's not a particularly efficient approach if you have many off-site links. Unless you like making work for yourself.

God forbid we should ever have to do this for every new window link…


<a
href="http://google.com/"
onclick="window.open(this.href, 'popupwindow',
'width=400,height=300,scrollbars,resizable');
return false;"
>

There are a number of other reasons why, imho, that method falls short of how we should be handling this kind of thing today.

_Aerospace_Eng_
12-09-2005, 12:57 PM
Here is one way without using target="_blank" of course it requires JS but if JS is disabled the use just gets taken to the page anyways in the same window.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
<!--
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;
-->
</script>
</head>

<body>
<a href="http://www.codingforums.com" rel="external">Coding Forums</a>
</body>
</html>

Jan
12-09-2005, 01:44 PM
Not without a url argument in the window.open method it doesn't. ;)

My mistake, sorry. This is what happens when I write in a hurry. :D Nevertheless, I seldom use forced window links and I can imagine a method like this would be very tiresome in the long run.

Bill Posters
12-09-2005, 01:59 PM
<a href="http://www.codingforums.com" rel="external">Coding Forums</a>[/code]
Fine if you don't have many links to address and don't mind obtrusive js - or if not all your off-site links target new windows.

HWChicago
12-09-2005, 07:17 PM
Hi,

I have something of a related problem. I have a link that I need to open in a new window. However, because of certain program limitations I can't use javascript. All I can do is use something on the order of _blank. Is there any way to control the size of the window that opens with this or any other html command?

thanks

_Aerospace_Eng_
12-09-2005, 08:00 PM
No you need javascript to control the window size.

HWChicago
12-09-2005, 08:13 PM
bah humbug,

ok thanks for the heads-up, guess I can stop wasting my time on that one.

tim



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum