Jump to content

target attribute in Strict XHTML


ColMatrix
 Share

Recommended Posts

Hi AllI am currently doing a website and...came to a hurdle...seems silly and easy to solve (or so I thought), I have had a look around on W3Schools (obviously) and googled it but could not find anything anywhere (also checked the forums too, nothing).Any suggestions on how to make my <a> tag (open in a new window) and keeping it XHTML strict?Many ThanksCol

Link to comment
Share on other sites

The target attribute has never been a part of Strict html. You can use it with Transitional, if you are willing to "downgrade" your code a bit. :)Since target is actually not structure or format, but browser behaviour (how to open a document with the browser), w3c says that it should be achieved with javascript.<a href="#" onclick="window.open('URL')">Link descr.</a>

Link to comment
Share on other sites

You can(and actually must) do this with java Script and to be more precise: DOM. The code you need for the JS file:

function applyPopups(){  a = document.getElementsByTagName('a');	  for(i=0; i<a.length; i++)  {    if(a[i].getAttribute('rel') && a[i].getAttribute('rel') == 'external')    {      a[i].onclick = function()      {        url = this.getAttribute('href');        window.open(url,'popup','width=200,height=400');        return false;      }    }  }}	window.onload = applyPopups;

And the <a> tag would have to have a rel attribute with value "external" for this to work. Like this:

<a href="the_link.html" rel="external">Link</a>

[edit] At the time of looking for the info, Jonas had written a post before me. His solution also works, but note that it's not as managable as this one, especially if you want to use other target attrbiutes as well. Using this method, you could define few values for the rel attribute and practically enable yourself the target attribute as if this was transitional XHTML. If you want to change the target you may either edit the JS file to make all corresponding links to perform like the newly desired attribute OR rename only a simple attribute if you want only that particular to change.[/edit]

Edited by boen_robot
Link to comment
Share on other sites

  • 3 weeks later...

Hi GuysI have been creating the web page (checking in Firefox) when I use either examples it never works properly in internet explorer.If I use Jonas example it says:"Page cannot be displayed" and in the address bar "C:\Root Folder\undefined"And when I use boen_robots code it opens it up...not in the dimensions I have specified and not in a external window...I have ensured javascript is enabled on both browsers...any ideas?Much appreciated, Col

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...