| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Opening Hyperlink In New Window Using Xhtml 1.0 Strict
#1
Posted 29 January 2008 - 05:30 AM
I would really like it if someone here at trap17 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.
#2
Posted 29 January 2008 - 05:59 AM
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.
#3
Posted 29 January 2008 - 07:16 AM
#4
Posted 29 January 2008 - 07:27 AM
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.
#5
Posted 29 January 2008 - 10:12 AM
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
#7
Posted 08 January 2010 - 08:11 PM
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 shanReply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users















