Jump to content
ColMatrix

target attribute in Strict XHTML

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

Share this post


Link to post
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>

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thx alot work now...just got to try to edit the JS code...eeek, Thx a lot for the support guys and help guysCol

Share this post


Link to post
Share on other sites

Excellent sorted it...just removed the size dimensions and it automatically opened into a window (meaning no control removed).Thx Col

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...