Why do I need this plugin?

Ok. Let’s say you have a page full of links that you need to tweak. All the “external” links (linking to someone else’s server) need to open in a new window, and also need a class added to them that displays a little “popup” icon. All the “internal” links need to have a few of the current page’s query string parameters propagated through to them.

And all this needs to happen via JavaScript because your page caching strategy doesn’t allow you to change these link target or href attributes for every user.

So, when you’re only dealing with relative links, this is pretty easy. You know they’re all “internal”, while all the absolute links are “external”. Well, except when they aren’t. Just because a URL is absolute doesn’t mean it goes to someone else’s server. Some content management systems like to publish absolute URLs for internal pages. Sometimes your “content guy” just enters them that way. And in IE6/7, even relative URLs in href, src, or other “URL” attributes can’t always be differentiated from absolute URLs (due to a known bug).

And the same thing goes for fragments. What do I mean by fragment? I consider a “fragment” to be any absolute or relative URL that, when navigated to, only changes the current page’s location.href “hash”. Fragments are used in single-page apps as a simple way to push a new state onto the browser history (see jQuery BBQ for some great examples of this).

Normally, you could just select $("a[href^=#]") to get a collection of all a elements that have an href starting with “#”. These all contain fragments. Well, except in IE6/7, where no href will ever start with “#” because of that aforementioned bug! That’s where this plugin comes in. It does all the dirty work, so you don’t have to.

Since this is a very simple plugin, these are only a few very simple examples. Check out the documentation and live example for detailed usage information.

Also, you may have noticed that many of these examples reference jQuery BBQ. That’s because these plugins complement each other. They are different enough to warrant separating them, but don’t be surprised if you find yourself using both of them together.

If you have any non-bug-related feedback or suggestions, please let me know below in the comments, and if you have any bug reports, please report them in the issues tracker, thanks!

jQuery urlInternal allows you to easily test internal-, external-, or fragment-ness for any relative or absolute URL. Includes element filtering methods and pseudo-selectors.\n\nThis plugin and the [jQuery BBQ](http://benalman.com/projects/jquery-bbq-plugin/) plugin supersede the URL Utils plugin.