Jump to content
xisto Community
csp4.0

Opening Hyperlink In New Window Using Xhtml 1.0 Strict

Recommended Posts

My website (currently under construction) is all going well until I realized that the XHTML 1.0 Strict DTD does not allow the target="_blank" attribute. How would I find a way around this? I'm used to using XHTML 1.0 Transitional, but I want this website to be Strict for a change.I would really like it if someone here at Xisto can give me some css that allows them to be opened in a new window. I have searched on Google and only found ways that include writing my own DTD (which I don't want to do), use javascript, and use another doctype.All of those things, I don't want to use. So it would really help if there is any way at all to open up a new window using CSS.

Share this post


Link to post
Share on other sites

Nope, can't be done via CSS with an XHTML Doctype.Javascript would be the recommended method, but consider that the rule against opening up new windows is there for a reason. Let the client decide which windows (tabs) get opened in a browser... that is the intent of the restriction in XHTML.

Share this post


Link to post
Share on other sites

In this era of tabbed browsing, different browsers take different understandings to being asked to open a link in a new window. Some take this literally, and so open an entire new browser window, while others take the logical route of opening a new tab. Then there is the possibility that the person viewing your site has ad-blocking or popup-blocking software running. They may well automatically prevent your link from opening a new window. As you can't necessarily be sure what will happen, it is best to go with something that will work instead. Let the browser and user decide what to do. Leave your link with no target, then the user can decide to open a new tab or window if they want, or to open the link in the existing tab/window.

Share this post


Link to post
Share on other sites

i think in this case, the only method is to use javascript.

i don't understand why you don't want to use javascript - javascript has got to be my favourite web-designing language, since you can do almost anything with javascript (if you really tried, and used document.write a lot, you could even (try to) design a whole webpage with javascript!).

i just found a handy code that i used to use (used to because i don't care about validation anymore - all i care about is if it works in all browsers, since my document comes up with 100 errors anyway. i prefer to stick to ' target ="_blank" '). it is javascript, cross-browser and works 100%:

addLoadEvent(externalLinks);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";	}}function addLoadEvent(func) {  var oldonload = window.onload;  if (typeof window.onload != 'function') {	window.onload = func;  } else {	window.onload = function() {	  oldonload();	  func();	}  }}

then, all you have to add to your links is ' rel="external" '. an example:

<a href="somepage.html" rel="external" title="this page opens in a new window">new window link</a>

hope i helped.

Share this post


Link to post
Share on other sites

The reason I don't want to use javascript is the fact that I am using a redirection service (http://www.freedomain.pro/) and it requires that I put a picture linking back. I can't modify the code so that is why I want a CSS code that opens the normal anchor tags in a new window and manually putting the nostyle tags in the ones I don't want to open to a new window.But now that I think about it. There doesn't look like a way to do it in the original way, so I guess that the javascript way is the only way. Or I might just 'cheat' and write my own DTD... hehe :o

Share this post


Link to post
Share on other sites
opening new browser windowsOpening Hyperlink In New Window Using Xhtml 1.0 Strict

personally I go by the rule that if it's a link on the same site, NOT to target to a new browser window, HOWEVER, I think that ALL links that are OUTSIDE the website, should be opened in a new browser window. I find it always higly irritating, if I have been warped away from the site where I still want to stay for a while, and just want to check a link that has been offered.

-reply by shan

Share this post


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

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.