Recent Posts
- (09/10) Fixing Warning: the ECDSA host key for 'github.com' differs from the key for the IP addressTAGS:Web Server Admin
- (12/26) CakePHP 3 - Getting List of Column Definitions from a Table (like schema())TAGS:CakephpCake3
- (09/14) Change Order of Loaded Behaviors in CakePHP 3TAGS:Cake3CakephpWeb ProgrammingPhp
- (05/29) CakePHP 3 - Accept JSON Header Only Working When Debug FalseTAGS:Web ProgrammingCakephpCake3
- (05/23) Remove All Events from Google Calendar (Reset Calendar)TAGS:Web ProgrammingPhp
- (11/08) Google Tag Manager (GTM) Not Firing Default PageView EventTAGS:Web ProgrammingJavascriptGoogle Tag Manager
- (10/13) In PHP, how do you get __toString() Magic Method Result without calling echo?TAGS:CakephpCake3Cakephp 13PhpWeb Programming
- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
Subscribe to my feed
MainelyDesign.com Blog
Using Jquery for target="_blank" and strict xHTML
Posted on 12/28/2009 at 03:27 pm by Kevin Wentworth
Viewed 15,378 times | 0 comments
If you like to see the little green check mark that HTML Validator shows when your HTML is 100% valid, you'll love this little trick. Thanks to badlydrawntoy.com.
Target="_blank" Breaks xHTML Strict Guidelines
When you include the target attribute, your HTML will break the standards guideline for xHTML strict. If you are using this doctype, you must use jquery to make your markup valid: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">.
Use jquery to open a new window (instead of target="_blank")
The following javascript code assumes you want all urls that start with http:// to open in a new window (target="_blank"). All relative links, /index.php, page.php, etc., won't be changed. However, all href's that begin with http will be opened in a new window:
- $(document).ready( function() {
- $('a[href^=http]').click( function() {
- window.open(this.href);
- return false;
- });
- });
If you only want to target links with a class of external, <a class="external" ...> use the following code:
- $(document).ready( function() {
- $('a.external').click( function() {
- window.open(this.href);
- return false;
- });
- });
If you want to use this method but use the rel="" attribute, check out this post.
Cheers,
-Kevin Wentworth
Tags for Using Jquery for target="_blank" and strict xHTML
Jquery | Tutorial | Example | Web Design | Hack
Comments for this Posting
No comments. Be the first to post a reply.
Sorry, comments are closed for this posting.
Please Email Kevin if you have any questions. Thanks!