I had made a post a few days ago regarding the problem with embedding flash (swf) into XHTML and still validating. That was an extremely simple fix, all you really had to do was remove code to get it to work (in other words, you optimized your code).
Getting XHTML to validate while using the target="_blank" value, on the other hand, takes a bit of code. Not that this is a problem, we’ve found the code you need!
First off, here’s the problem:
|
1 |
<a href="/test.html" target="_blank">testing</a> |
Here is what you’ll have after we fix the problem:
|
1 |
<a href="/test.html" rel="blank">testing</a> |
I’ll get straight to the point, if you want to dissect the code you can probably Google a line or two from it and get the page where I found the information.
This is what you put in your <head></head> tags:
|
1 |
<script type="text/javascript" src="/include/target.js"></script> |
This is what you put in the file located at /include/target.js:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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") == "top") {
anchor.target = "_top";
} else if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank") {
anchor.target = "_blank";
}
}
}
window.onload = externalLinks; |
That’s it! The original code I found was lacking, it only had the option to use an external window (_blank). My better code lets you also do a target="_top" command with the rel="top" method. So now you can use both rel="top" and rel="blank".
Related posts:
- Embedding Flash Files With Valid XHTML (Strict) I’m sure a lot of people want to know the...
- Valid XHTML Vertical Centering Using CSS The simplest method to vertically center your elements while using...
- Rotating Script for Text Ads, Banner Ads or Interstitials (or Anything Else!) The following are simple instructions to create a script to...
- Reduce the Microsoft Windows 7 WinSxS Folder’s Size You can reduce the Microsoft Windows 7 WinSxS folder’s size...
- Generate an OpenSSL CSR for Apache2 and ModSSL Generating an encrypted RSA key You can skip this step...
- Opera AdBlock – Simple Ad Blocking – urlfilter.ini, No HOSTS Ad Blocking The best way to block ads with Opera...

0 Comments.