Recent Posts
- (02/24) Calling an Element from a Helper TAGS:CakephpWeb ProgrammingUsageTutorialExample
- (10/14) Forcing A Single Join in CakePHP PaginationTAGS:CakephpCakephp 13DatabaseErrorsHabtmMysqlMssqlWeb ProgrammingUsage
- (08/11) Inserting NOW() into MySQL Using CakePHPTAGS:CakephpDatabaseMysqlMssqlWeb ProgrammingUsage
- (08/07) Best PaginateCount for CakePHP - with Group By SupportTAGS:CakephpBehaviorsWeb ProgrammingUsageDatabaseExampleMysqlHabtmHack
- (04/03) CakePHP Error Messages Not Showing on FormTAGS:CakephpCakephp 13Web ProgrammingErrorsUsage
- (02/06) Sorting Paginated Results Using a Related Model Field in CakePHPTAGS:CakephpWeb ProgrammingUsageExample
- (11/02) Changing CakePHP's Model useTable on the FlyTAGS:CakephpWeb ProgrammingMysqlDatabaseExampleTutorial
- (10/18) The Funniest Error Message Ever - Thank You EclipseTAGS:EclipseWeb ProgrammingErrorsHumorWindowsUsageSoftwarePhpCakephp
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 3,293 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
