Jump to content

Replacement of 'Target' Attribute in 4.01 Strict?


Nago

Recommended Posts

I'm attempting to make any off-site links open in a new window instead of the window the site is in, normally I'd do something with the TARGET attribute for the "a" tag, but that is invalid in 4.01 strict, and I am very dead-set on staying with that dtd.Javascript would of course work, as long as I can get it to work in 4.01 :>Suggestions?

Link to comment
Share on other sites

For any curious;Found an answer with a bit of googling. The target element has been deprecated due to US law forbidding opening windows without that user's consent (though, I'd consider clicking the link consent enough, compared to some guerilla tactics used by ads)the workaround inevitably uses javascript, however. you can put something like this in your header (or .js file, etc):

<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>

and then per each link you wish to link externally, you can use the rel attribute for the anchor tag instead, like this:<a href="http://www.w3schools.com" rel="external">http://www.w3schools.com</a>For those who have disabled javascript, this acts as a regular link.credit for this one goes to sitepoint.com and Kevin Yank.

Link to comment
Share on other sites

The target element has been deprecated due to US law forbidding opening windows without that user's consen

sorry to hijack the thread but i think thats just stupid.as long as you give the user warning about it opening in a window..then surely thats fine??and i agree with scott, the US isn't all the world.
Link to comment
Share on other sites

Actually, the reason the target attribute isn't valid is because html is website structure, and shouldn't have any influence on things that are defined in OS settings. That's also the reason the css for scrollbar isn't valid, because the scrollbar is set in the browser.

Link to comment
Share on other sites

Actually, the reason the target attribute isn't valid is because html is website structure, and shouldn't have any influence on things that are defined in OS settings. That's also the reason the css for scrollbar isn't valid, because the scrollbar is set in the browser.

hrm~! that makes sense as well. I found a lot of webtalk about how it violated some US law, so it was deprecated. What with the US being big, scary, and largely confused, I figured this was pretty much true, even though the web applies to much more than the US- we do have a pretty big influence on many things we shouldn't.Thanks for the Info, Jonas.
Link to comment
Share on other sites

You can open a new window, but you^re supposed to use javascript function window.open instead of html attribute target.

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
×
×
  • Create New...