Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 14th, 2005, 3:37 PM   #1
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
using the target attribute in XHTML1.1

There's a target module in XHTML1.1 but I've no idea how to use it. I've tried putting all kinds of things in the !DOCTYPE, but the validator either spits out syntax error in the DTD or target isn't an attribute.
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted.
Got 'Nux?—GNU/Linux and other free software support.
It's GNU/Linux, not just Linux.
a thing is offline   Reply With Quote
Old Nov 14th, 2005, 3:42 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
This site should help:

http://golem.ph.utexas.edu/~distler/...s/zeldman.html
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 14th, 2005, 3:55 PM   #3
Agent 47
Hobbyist Programmer
 
Agent 47's Avatar
 
Join Date: Nov 2005
Posts: 122
Rep Power: 3 Agent 47 is on a distinguished road
Ok, first off, you shouldn't be using XHTML1.1 - it is way ahead of its time,
and until IE supports the application/xhtml+xml content type [which, by the
way, you are required to serve it as], it is pointless.

Now, as for the links, the best way to do this, is using JavaScript.

Add a 'rel' attribute to all your links, like so:
<a href="#" rel="external">This will open in a new window</a>
<a href="#">This will open in the current window</a>
and have a small script run onload, like so:
<script type="text/JavaScript">
//<![CDATA[
function hookExternalLinks()
{
	var links=document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++)
	{
		if (links[i].rel=='external') links[i].target='_blank';
	}
}
window.onload=hookExternalLinks;
//]]>
</script>
--47.
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"
Agent 47 is offline   Reply With Quote
Old Nov 14th, 2005, 4:06 PM   #4
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
I really don't care if Trident doesn't support XHTML. Every other modern rendering engine I've come across except Lynx supports it. XHTML1.0's been around since 1999 and 1.1 since 2001; there's no excuse for not supporting it now other than an unmaintained project.

And using rel and that JavaScript instead of directly putting target="_blank" is pointless.
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted.
Got 'Nux?—GNU/Linux and other free software support.
It's GNU/Linux, not just Linux.
a thing is offline   Reply With Quote
Old Nov 14th, 2005, 4:13 PM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
a_thing i think he's making a suggestion to help get past xHTML validation...
__________________

tempest is offline   Reply With Quote
Old Nov 14th, 2005, 4:23 PM   #6
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
But it's still invalid.
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted.
Got 'Nux?—GNU/Linux and other free software support.
It's GNU/Linux, not just Linux.
a thing is offline   Reply With Quote
Old Nov 14th, 2005, 4:26 PM   #7
Agent 47
Hobbyist Programmer
 
Agent 47's Avatar
 
Join Date: Nov 2005
Posts: 122
Rep Power: 3 Agent 47 is on a distinguished road
Quote:
Originally Posted by a thing
I really don't care if Trident doesn't support XHTML. Every other modern rendering engine I've come across except Lynx supports it. XHTML1.0's been around since 1999 and 1.1 since 2001; there's no excuse for not supporting it now other than an unmaintained project.

And using rel and that JavaScript instead of directly putting target="_blank" is pointless.
You can not care all you want, but when you are alienating 80+% of your
users just because of your 'ideals', then you are an idiot.

Why is setting the target attribute pointless? You asked how to have your
links open in new windows while still using strict HTML, and I answered.

If you don't want help, don't ask for it.
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"
Agent 47 is offline   Reply With Quote
Old Nov 14th, 2005, 4:39 PM   #8
Agent 47
Hobbyist Programmer
 
Agent 47's Avatar
 
Join Date: Nov 2005
Posts: 122
Rep Power: 3 Agent 47 is on a distinguished road
If you really have a problem setting the target attribute, then you can use
something like this instead.
<script type="text/JavaScript">
//<![CDATA[
function hookExternalLinks()
{
	var links=document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++)
	{
		if (links[i].rel=='external')
		{
			links[i].onclick=makeExternal;
			links[i].onkeydown=makeExternal;
		}
	}
}
function makeExternal(event)
{
	if ((typeof(event)=="undefined")||(!event))event=window.event;
	var lnk=event.target||event.srcElement;
	return !window.open(lnk.href);
}
window.onload=hookExternalLinks;
//]]>
</script>
Has exactly the same effect.

--47.
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"
Agent 47 is offline   Reply With Quote
Old Nov 14th, 2005, 5:07 PM   #9
Agent 47
Hobbyist Programmer
 
Agent 47's Avatar
 
Join Date: Nov 2005
Posts: 122
Rep Power: 3 Agent 47 is on a distinguished road
IE, in its default settings, can't handle the application/xhtml+xml mime
type, and thus brainfarts when it sees it.

Have a look at this page in Firefox to see what it is meant to look like,
then look at it in IE...
http://garyblue.port5.com/webdev/xhtml/xhtmldoc.html

Now, look at this page to see what happens when your XHTML has an
error in. Again, the proper result can be seen in Ff, while IE fecks it up.
http://garyblue.port5.com/webdev/xht...-xhtmldoc.html

<edit> Oh, Ooble deleted his last post while I was typing this up... :/
Nevemind. Nothing to see here - move along people...


--47.
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"
Agent 47 is offline   Reply With Quote
Old Nov 14th, 2005, 5:14 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Yeah... felt it was too harsh. Not in a fantastic mood right now - sorry 'bout that.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC