Your generous donation allows me to continue developing and updating my code!
jQuery urlInternal allows you to test whether any URL is internal or external, using an easily configurable RegExp. It can also test whether any URL is a fragment that will only change the location.hash, instead of navigating to a new page, even in IE6/7! Where would you use this? Here are a few basic examples, I'm sure you can come up with more:
Some common usage examples
// Open every external link in a new window. $("a:urlExternal").attr( "target", "_blank" ); // Pass document query string through to all internal links and forms (see jQuery BBQ at // http://benalman.com/projects/jquery-bbq-plugin/ for the query string methods). $("a, form").urlInternal().querystring( $.deparam.querystring() ); // Add an onclick handler to all fragment links (see jQuery BBQ for the pushState and fragment // methods). In most browsers, you can do $("a[href^=#]") but that won't always work in IE6/7! // Either make your selector more robust, or use :urlFragment! $("a:urlFragment").click(function(){ var frag = $.param.fragment( $(this).attr( 'href' ) ); $.bbq.pushState({ page: frag }); return false; });
Tests
// For each of the example spans (at the bottom), test the URL in the "data-url" attribute. $.elemUrlAttr({ span: 'data-url' }); // In tests 1-3, .urlInternal and .urlExternal are tested for the item in each table row, // using each of these values. $.urlInternalHost( "www" ); // 1 $.urlInternalHost( "foo" ); // 2 $.urlInternalRegExp( /^(?:https?:)?\/\/(?:(?:www|foo)\.)?benalman.com\// ); // 3 // In test 4, .urlFragment is tested for the item in each table rom.