MyBB Community Forums

Full Version: External links in XHTML 1.1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Well as you all know the target="_blank" with links is deprecated in XHTML 1.1.
So for you XHTML fanatics out there here is a solution to the problem.

Here is a javascript solution, I made this for MyBB. As you all know it would be a lot more work then just this to make it validate as XHTML 1.1. But this can be used anywhere and on any page.
MyBB.externalLinks = function()
{
	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.onclick = function(){ window.open(anchor.href); return false; };
			anchor.onkeypress = function(){ window.open(anchor.href); return false; };
		}
	}
}

window.onload = MyBB.externalLinks; <!-- This will load on onload and set the links with onclick and onkeypress events. // -->

Then your link would look like.
<a href="http://www.mybboard.net" rel="external">MyBB</a>
It will find any link with rel="external" within the a tag.
Nicely done!

I don't think I'll be converting to XHTML 1.1 quite yet though Toungue 1.0 is good enough for me.
I only just got around to making my website XHTML 1.0 compliant, maybe this will get done in another 5 years Toungue
XHTML 1.1 isn't that hard to accomplish if you don't use tables. If you do there are a lot deprecated tags in XHTML 1.1.
CraKteR Wrote:XHTML 1.1 isn't that hard to accomplish if you don't use tables. If you do there are a lot deprecated tags in XHTML 1.1.
Hmmm...I validated my site in 1.1 and it only got 5 errors...and they all looked pretty simple changes. Maybe I'll do it at some point in the near future Toungue
my board have 14 error, and mybboard have 18 error Toungue
http://validator.w3.org/check?uri=http%3...=XHTML+1.1
I bet if you fix those errors you'll get more.
Thanks for the info
Stupid XHTML... They're idiots. Why did they remove it!! To make everyone's lives harder??
Tikitiki Wrote:Stupid XHTML... They're idiots. Why did they remove it!! To make everyone's lives harder??
It was never meant to be like this. HTML was never meant to go beyond CERN and so Tim Berners-Lee didn't care about structure and consistency. Of course that all got screwed up when the public wanted in on it Toungue

I do think that it is ridiculous using a language that can be disabled (Javascript) to perform a basic function like opening in a new page / tab. Sure most people have it enabled, but there are something like 5% who don't for whatever reason.
Pages: 1 2