mbt Posted August 23, 2010 Share Posted August 23, 2010 hi,i would like to use image as a link and website should open in new window,how to do in XHTML?HTML code: <a href="http://w3schools.invisionzone.com/index.php?" target="_blank"><img src="http://w3schools.invisionzone.com/style_images/6_logo.png" border="0"></a> Link to comment Share on other sites More sharing options...
Ingolme Posted August 23, 2010 Share Posted August 23, 2010 The code you provided should work just fine. You just need an ALT attribute on the image and to close it with /> in order to make it compliant with XHTML Transitional. Link to comment Share on other sites More sharing options...
mbt Posted August 23, 2010 Author Share Posted August 23, 2010 well, i should've said i use XHTML Strict,and i would like to have website green (validated) Link to comment Share on other sites More sharing options...
mbt Posted August 23, 2010 Author Share Posted August 23, 2010 This is closer: <a href="http://w3schools.invisionzone.com/index.php?" target="_blank"><img src="http://w3schools.invisionzone.com/style_images/6_logo.png"alt="image description" style="border-style: none" /></a> Still, error: there is no attribute "target" Link to comment Share on other sites More sharing options...
ShadowMage Posted August 23, 2010 Share Posted August 23, 2010 You can't use the target attribute in Strict. (It's deprecated) The only way to open a new window with a Strict DTD is to use JavaScript. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 24, 2010 Share Posted August 24, 2010 As said before to validate in strict1) img must end with "/>"2) img must contain alt attribute3) you must also enclose <a><img /></a> within a block element<div ="gallery"><a href="http://w3schools.invisionzone.com/index.php?"><img src="http://w3schools.invisionzone.com/style_images/6_logo.png"alt="image description" style="border-style: none" /></a></div>the target="_blank" is not supported in Strict doc type, in transitional Yes, Strict No!To will either have to convert to Transitional or use javascript within Strictyou can target all images within the div container using onload to assign an id ref, and onclick function to assign javascript target functionwindow.onload=function(){var ParentContainer = document.getElementById("gallery");var ChildAnchors = ParentContainer.getElementsByTagName("a");for(i=0;i<ChildAnchors.length;i++){ChildAnchors.id="image"+i;ChildAnchors.onclick = function() {gohere(this);}}}function gohere(element){document.getElementById(element.id).target="_blank";}if javascript is disabled, it will open in the same window. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.