Share this post! | Vote this! |
|
It doesn’t matter if you are just starting out with jQuery or have been working with it for a while; you probably have some magic in your bag that you reuse in your projects.
Open Links in New Windows
If you are like me, you don’t like your markup to not validate. Well in XHTML 1.0 Strict you cannot use thetarget="blank"
attribute on anchor tags. You may also want to open all external links in new windows to try to keep your visitor on your site. Here is a bit of jQuery that will allow you to hop over this problem and open all external links in new windows.//check that the DOM is ready $(document).ready(function() { //select all anchor tags that have http in the href //and apply the target=_blank $("a[href^='http']").attr('target','_blank'); });Presto! All external links will now open in a new window, allowing your page to remain for the user to return to. If you use a lot of external document links such as PDF or DOC files you could create several of these rules to load these documents in a new window.
More...
0 comments:
Post a Comment