Nago Posted March 29, 2006 Share Posted March 29, 2006 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 More sharing options...
Nago Posted March 29, 2006 Author Share Posted March 29, 2006 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 More sharing options...
scott100 Posted March 29, 2006 Share Posted March 29, 2006 That's interesting i never knew that target was deprecated.Is this just a US law? the web is worldwide after all not just US... Link to comment Share on other sites More sharing options...
real_illusions Posted March 29, 2006 Share Posted March 29, 2006 The target element has been deprecated due to US law forbidding opening windows without that user's consen<{POST_SNAPBACK}> 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 More sharing options...
Jonas Posted March 29, 2006 Share Posted March 29, 2006 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 More sharing options...
Nago Posted March 30, 2006 Author Share Posted March 30, 2006 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.<{POST_SNAPBACK}> 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 More sharing options...
htmlkid Posted April 4, 2006 Share Posted April 4, 2006 cant open another window? thats just donkey sausage Link to comment Share on other sites More sharing options...
Jonas Posted April 4, 2006 Share Posted April 4, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now