blogsmith Posted October 21, 2010 Share Posted October 21, 2010 I received a suggestion as follows - between dotted line...............................You can still use XHTML strict and target hyperlinks and yes still have it pass with W3C validation. You can do this with Javascript between your heading tags you place this code:$(function(){$('a[rel=external]').attr('target','_new');});Then in every link you want to target the new window add rel="external" to the anchor. That will reference the javascript function and open it in a new window and all of which will validate in W3C as XHTML strict. Hope this helps. ..............................I will like to add more codes to the above so that I can test it at http://validator.w3.org/Will this do?................................<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html dir='ltr' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'> <head> <a href="http://www.w3schools.com" target="_blank" rel="external">W3Schools</a></head></html>............................If not how can I make the above complete enough to submit for validation? Link to comment Share on other sites More sharing options...
blogsmith Posted October 21, 2010 Author Share Posted October 21, 2010 sorry, maybe like this:................................<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html dir='ltr' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'> <head> </head><a href="http://www.w3schools.com" target="_blank" rel="external">W3Schools</a></html>............................ Link to comment Share on other sites More sharing options...
Synook Posted October 21, 2010 Share Posted October 21, 2010 Well, if you use the JavaScript you can remove the target attribute, as the script adds it back in dynamically. Link to comment Share on other sites More sharing options...
blogsmith Posted October 21, 2010 Author Share Posted October 21, 2010 Well, if you use the JavaScript you can remove the target attribute, as the script adds it back in dynamically.I tested adding the script just before </head> for my test blog athttp://testing-blogger-beta.blogspot.com/specifically athttp://testing-blogger-beta.blogspot.com/2...new-window.htmland made this link<a href="http://www.bloggertipsandtricks.com" rel="external">Blogger Tips and Tricks</a>but the link still open in the same window? Link to comment Share on other sites More sharing options...
Synook Posted October 21, 2010 Share Posted October 21, 2010 Maybe you want to make it set the value of the target attribute to _blank, not _new?P.S. target is deprecated for a reason... Link to comment Share on other sites More sharing options...
dsonesuk Posted October 21, 2010 Share Posted October 21, 2010 From what i can see the code is not within any script tags as in <script type="text/javascript">$(function(){$('a[rel=external]').attr('target','_new');});</script>I also don't any links to jquery libraries files at all. Link to comment Share on other sites More sharing options...
Ingolme Posted October 21, 2010 Share Posted October 21, 2010 Adding the target attribute with Javascript is just cheating against the validator.For what it's worth, you could also be creating font and center tags with the DOM methods and the validator would still consider it correct.If you're going to use Javascript, you might as well do it correctly. Loop through the links and bind an onclick even which runs the window.open() method instead.But if you really absolutely need the target attribute, just switch to a transitional DTD. Link to comment Share on other sites More sharing options...
aspnetguy Posted October 21, 2010 Share Posted October 21, 2010 I like to use the following method as it degrades nicely if a popup blocker is being used. <a href="some url" rel="external">My Link</a>...<script type="text/javascript">var links = document.getElementsByTagName("a");for(var i=0;i<links.length;i++) { if(links[i].getAttribute('rel') == 'external') { links[i].onclick = function() { return !window.open(this.href); }; }}</script> What that click handler does is try to open the link in a new windows. If it fails, fior whatever reason, it will then open the link in the current window. This way if the user has a popup blocker they can still access the link. Link to comment Share on other sites More sharing options...
real_illusions Posted October 22, 2010 Share Posted October 22, 2010 From what i can see the code is not within any script tags as in <script type="text/javascript">$(function(){$('a[rel=external]').attr('target','_new');});</script>I also don't any links to jquery libraries files at all.Exactly right. That bit of Javascript is jQuery, so you need to link to the jQuery library.The target attribute is coming back in HTML5, so you could use that, but bear in mind the lack of consistent support for HTML5 features across all browsers. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.