NOTE: Better examples coming soon. See the documentation

This is the only link you should click: ?a=X&b=Y&c=Z#n=1&o=2&p=3

(href / action changes will appear in orange, while target changes appear in magenta)

internal links, qs params other than 'b' should propagate

./   ./?a=X&c=Z
../   ../?a=X&c=Z
?test=&a=1&a=2&b=boo   ?test=&a=X&b=boo&c=Z
?test=&a=1&a=2&b=boo#test-anchor   ?test=&a=X&b=boo&c=Z#test-anchor
foo   foo?a=X&c=Z
foo#test-anchor   foo?a=X&c=Z#test-anchor
foo/   foo/?a=X&c=Z
foo/bar.html?baz=123   foo/bar.html?baz=123&a=X&c=Z
bar.html?test=&a=1&a=2&b=boo   bar.html?test=&a=X&b=boo&c=Z
/foo   /foo?a=X&c=Z
/foo/   /foo/?a=X&c=Z
/foo/bar.html?baz=123   /foo/bar.html?baz=123&a=X&c=Z
/bar.html?test=&a=1&a=2&b=boo   /bar.html?test=&a=X&b=boo&c=Z
https://benalman.com/   https://benalman.com/?a=X&c=Z
http://www.benalman.com/   _blank
http://www.benalman.com/foo#test-anchor   _blank
http://www.benalman.com/foo/#test-anchor   _blank
https://benalman.com/foo/bar.html   https://benalman.com/foo/bar.html?a=X&c=Z
https://benalman.com/foo/bar.html?baz=123   https://benalman.com/foo/bar.html?baz=123&a=X&c=Z
https://benalman.com/foo/bar.html?baz=123&test=   https://benalman.com/foo/bar.html?baz=123&test=&a=X&c=Z
https://benalman.com/bar.html?test=&a=1&a=2&b=boo   https://benalman.com/bar.html?test=&a=X&b=boo&c=Z

external links, target should be changed to _blank

https://benalman.com:81/   _blank
http://foo.benalman.com/   _blank
http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo   _blank
https://foo.benalman.com/   _blank
http://bar.benalman.com/   _blank
https://benalman.com/   https://benalman.com/?a=X&c=Z
https://www.benalman.com/   https://www.benalman.com/?a=X&c=Z
https://google.com/   _blank
https://google.com/foo/bar.html?baz=123&test=   _blank
https://google.com/bar.html?test=&a=1&a=2&b=boo   _blank

other links, qs/target should be unchanged

#test-anchor
mailto:spam@benalman.com
javascript:alert('hello world')
ftp://ftp.example.com/foo/bar
irc://irc.example.com/foo/bar
arbitrary://irc.example.com/foo/bar

fragments, qs params other than 'b' should propagate

click: #
click: #foo   #foo=
click: #test=&a=1&a=2&b=boo
click: #baz=123

internal action form, qs params other than 'b' should propagate

action: ?mode=test   ?mode=test&a=X&c=Z

external action form, target should be changed to _blank

action: https://google.com/search?q=ben+alman   _blank

"internal" div, qs params other than 'b' should propagate

(with fake "foo" attribute) action: ?mode=test   ?mode=test&a=X&c=Z

"external" div, "bar" attribute should be set to "external"

(with fake "foo" attribute) action: http://google.com/search?q=ben+alman   external

debug

$.urlInternalHost('www');

urlInternalRegExp: /^https:\/\/(?:www\.)?benalman.com\//i

Internal?

$.isUrlInternal("./"): true
$.isUrlInternal("../"): true
$.isUrlInternal("?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("?test=&a=1&a=2&b=boo#test-anchor"): true
$.isUrlInternal("foo"): true
$.isUrlInternal("foo#test-anchor"): true
$.isUrlInternal("foo/"): true
$.isUrlInternal("foo/bar.html?baz=123"): true
$.isUrlInternal("bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("/foo"): true
$.isUrlInternal("/foo/"): true
$.isUrlInternal("/foo/bar.html?baz=123"): true
$.isUrlInternal("/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("https://benalman.com/"): true
$.isUrlInternal("http://www.benalman.com/"): false
$.isUrlInternal("http://www.benalman.com/foo#test-anchor"): false
$.isUrlInternal("http://www.benalman.com/foo/#test-anchor"): false
$.isUrlInternal("https://benalman.com/foo/bar.html"): true
$.isUrlInternal("https://benalman.com/foo/bar.html?baz=123"): true
$.isUrlInternal("https://benalman.com/foo/bar.html?baz=123&test="): true
$.isUrlInternal("https://benalman.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("https://benalman.com:81/"): false
$.isUrlInternal("http://foo.benalman.com/"): false
$.isUrlInternal("http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlInternal("https://foo.benalman.com/"): false
$.isUrlInternal("http://bar.benalman.com/"): false
$.isUrlInternal("https://benalman.com/"): true
$.isUrlInternal("https://www.benalman.com/"): true
$.isUrlInternal("https://google.com/"): false
$.isUrlInternal("https://google.com/foo/bar.html?baz=123&test="): false
$.isUrlInternal("https://google.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlInternal("#test-anchor"): undefined
$.isUrlInternal("mailto:spam@benalman.com"): undefined
$.isUrlInternal("javascript:alert('hello world')"): undefined
$.isUrlInternal("ftp://ftp.example.com/foo/bar"): undefined
$.isUrlInternal("irc://irc.example.com/foo/bar"): undefined
$.isUrlInternal("arbitrary://irc.example.com/foo/bar"): undefined
$.isUrlInternal("#"): undefined
$.isUrlInternal("#foo"): undefined
$.isUrlInternal("#test=&a=1&a=2&b=boo"): undefined
$.isUrlInternal("#baz=123"): undefined

External?

$.isUrlExternal("./"): false
$.isUrlExternal("../"): false
$.isUrlExternal("?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("?test=&a=1&a=2&b=boo#test-anchor"): false
$.isUrlExternal("foo"): false
$.isUrlExternal("foo#test-anchor"): false
$.isUrlExternal("foo/"): false
$.isUrlExternal("foo/bar.html?baz=123"): false
$.isUrlExternal("bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("/foo"): false
$.isUrlExternal("/foo/"): false
$.isUrlExternal("/foo/bar.html?baz=123"): false
$.isUrlExternal("/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("https://benalman.com/"): false
$.isUrlExternal("http://www.benalman.com/"): true
$.isUrlExternal("http://www.benalman.com/foo#test-anchor"): true
$.isUrlExternal("http://www.benalman.com/foo/#test-anchor"): true
$.isUrlExternal("https://benalman.com/foo/bar.html"): false
$.isUrlExternal("https://benalman.com/foo/bar.html?baz=123"): false
$.isUrlExternal("https://benalman.com/foo/bar.html?baz=123&test="): false
$.isUrlExternal("https://benalman.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("https://benalman.com:81/"): true
$.isUrlExternal("http://foo.benalman.com/"): true
$.isUrlExternal("http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlExternal("https://foo.benalman.com/"): true
$.isUrlExternal("http://bar.benalman.com/"): true
$.isUrlExternal("https://benalman.com/"): false
$.isUrlExternal("https://www.benalman.com/"): false
$.isUrlExternal("https://google.com/"): true
$.isUrlExternal("https://google.com/foo/bar.html?baz=123&test="): true
$.isUrlExternal("https://google.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlExternal("#test-anchor"): undefined
$.isUrlExternal("mailto:spam@benalman.com"): undefined
$.isUrlExternal("javascript:alert('hello world')"): undefined
$.isUrlExternal("ftp://ftp.example.com/foo/bar"): undefined
$.isUrlExternal("irc://irc.example.com/foo/bar"): undefined
$.isUrlExternal("arbitrary://irc.example.com/foo/bar"): undefined
$.isUrlExternal("#"): undefined
$.isUrlExternal("#foo"): undefined
$.isUrlExternal("#test=&a=1&a=2&b=boo"): undefined
$.isUrlExternal("#baz=123"): undefined

$.urlInternalHost('foo');

urlInternalRegExp: /^https:\/\/(?:foo\.)?benalman.com\//i

Internal?

$.isUrlInternal("./"): true
$.isUrlInternal("../"): true
$.isUrlInternal("?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("?test=&a=1&a=2&b=boo#test-anchor"): true
$.isUrlInternal("foo"): true
$.isUrlInternal("foo#test-anchor"): true
$.isUrlInternal("foo/"): true
$.isUrlInternal("foo/bar.html?baz=123"): true
$.isUrlInternal("bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("/foo"): true
$.isUrlInternal("/foo/"): true
$.isUrlInternal("/foo/bar.html?baz=123"): true
$.isUrlInternal("/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("https://benalman.com/"): true
$.isUrlInternal("http://www.benalman.com/"): false
$.isUrlInternal("http://www.benalman.com/foo#test-anchor"): false
$.isUrlInternal("http://www.benalman.com/foo/#test-anchor"): false
$.isUrlInternal("https://benalman.com/foo/bar.html"): true
$.isUrlInternal("https://benalman.com/foo/bar.html?baz=123"): true
$.isUrlInternal("https://benalman.com/foo/bar.html?baz=123&test="): true
$.isUrlInternal("https://benalman.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("https://benalman.com:81/"): false
$.isUrlInternal("http://foo.benalman.com/"): false
$.isUrlInternal("http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlInternal("https://foo.benalman.com/"): true
$.isUrlInternal("http://bar.benalman.com/"): false
$.isUrlInternal("https://benalman.com/"): true
$.isUrlInternal("https://www.benalman.com/"): false
$.isUrlInternal("https://google.com/"): false
$.isUrlInternal("https://google.com/foo/bar.html?baz=123&test="): false
$.isUrlInternal("https://google.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlInternal("#test-anchor"): undefined
$.isUrlInternal("mailto:spam@benalman.com"): undefined
$.isUrlInternal("javascript:alert('hello world')"): undefined
$.isUrlInternal("ftp://ftp.example.com/foo/bar"): undefined
$.isUrlInternal("irc://irc.example.com/foo/bar"): undefined
$.isUrlInternal("arbitrary://irc.example.com/foo/bar"): undefined
$.isUrlInternal("#"): undefined
$.isUrlInternal("#foo"): undefined
$.isUrlInternal("#test=&a=1&a=2&b=boo"): undefined
$.isUrlInternal("#baz=123"): undefined

External?

$.isUrlExternal("./"): false
$.isUrlExternal("../"): false
$.isUrlExternal("?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("?test=&a=1&a=2&b=boo#test-anchor"): false
$.isUrlExternal("foo"): false
$.isUrlExternal("foo#test-anchor"): false
$.isUrlExternal("foo/"): false
$.isUrlExternal("foo/bar.html?baz=123"): false
$.isUrlExternal("bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("/foo"): false
$.isUrlExternal("/foo/"): false
$.isUrlExternal("/foo/bar.html?baz=123"): false
$.isUrlExternal("/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("https://benalman.com/"): false
$.isUrlExternal("http://www.benalman.com/"): true
$.isUrlExternal("http://www.benalman.com/foo#test-anchor"): true
$.isUrlExternal("http://www.benalman.com/foo/#test-anchor"): true
$.isUrlExternal("https://benalman.com/foo/bar.html"): false
$.isUrlExternal("https://benalman.com/foo/bar.html?baz=123"): false
$.isUrlExternal("https://benalman.com/foo/bar.html?baz=123&test="): false
$.isUrlExternal("https://benalman.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("https://benalman.com:81/"): true
$.isUrlExternal("http://foo.benalman.com/"): true
$.isUrlExternal("http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlExternal("https://foo.benalman.com/"): false
$.isUrlExternal("http://bar.benalman.com/"): true
$.isUrlExternal("https://benalman.com/"): false
$.isUrlExternal("https://www.benalman.com/"): true
$.isUrlExternal("https://google.com/"): true
$.isUrlExternal("https://google.com/foo/bar.html?baz=123&test="): true
$.isUrlExternal("https://google.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlExternal("#test-anchor"): undefined
$.isUrlExternal("mailto:spam@benalman.com"): undefined
$.isUrlExternal("javascript:alert('hello world')"): undefined
$.isUrlExternal("ftp://ftp.example.com/foo/bar"): undefined
$.isUrlExternal("irc://irc.example.com/foo/bar"): undefined
$.isUrlExternal("arbitrary://irc.example.com/foo/bar"): undefined
$.isUrlExternal("#"): undefined
$.isUrlExternal("#foo"): undefined
$.isUrlExternal("#test=&a=1&a=2&b=boo"): undefined
$.isUrlExternal("#baz=123"): undefined

$.urlInternalRegExp('^https?://(?:(?:www|foo)[.])?benalman.com/');

urlInternalRegExp: /^https?:\/\/(?:(?:www|foo)[.])?benalman.com\//i

Internal?

$.isUrlInternal("./"): true
$.isUrlInternal("../"): true
$.isUrlInternal("?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("?test=&a=1&a=2&b=boo#test-anchor"): true
$.isUrlInternal("foo"): true
$.isUrlInternal("foo#test-anchor"): true
$.isUrlInternal("foo/"): true
$.isUrlInternal("foo/bar.html?baz=123"): true
$.isUrlInternal("bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("/foo"): true
$.isUrlInternal("/foo/"): true
$.isUrlInternal("/foo/bar.html?baz=123"): true
$.isUrlInternal("/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("https://benalman.com/"): true
$.isUrlInternal("http://www.benalman.com/"): true
$.isUrlInternal("http://www.benalman.com/foo#test-anchor"): true
$.isUrlInternal("http://www.benalman.com/foo/#test-anchor"): true
$.isUrlInternal("https://benalman.com/foo/bar.html"): true
$.isUrlInternal("https://benalman.com/foo/bar.html?baz=123"): true
$.isUrlInternal("https://benalman.com/foo/bar.html?baz=123&test="): true
$.isUrlInternal("https://benalman.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("https://benalman.com:81/"): false
$.isUrlInternal("http://foo.benalman.com/"): true
$.isUrlInternal("http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlInternal("https://foo.benalman.com/"): true
$.isUrlInternal("http://bar.benalman.com/"): false
$.isUrlInternal("https://benalman.com/"): true
$.isUrlInternal("https://www.benalman.com/"): true
$.isUrlInternal("https://google.com/"): false
$.isUrlInternal("https://google.com/foo/bar.html?baz=123&test="): false
$.isUrlInternal("https://google.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlInternal("#test-anchor"): undefined
$.isUrlInternal("mailto:spam@benalman.com"): undefined
$.isUrlInternal("javascript:alert('hello world')"): undefined
$.isUrlInternal("ftp://ftp.example.com/foo/bar"): undefined
$.isUrlInternal("irc://irc.example.com/foo/bar"): undefined
$.isUrlInternal("arbitrary://irc.example.com/foo/bar"): undefined
$.isUrlInternal("#"): undefined
$.isUrlInternal("#foo"): undefined
$.isUrlInternal("#test=&a=1&a=2&b=boo"): undefined
$.isUrlInternal("#baz=123"): undefined

External?

$.isUrlExternal("./"): false
$.isUrlExternal("../"): false
$.isUrlExternal("?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("?test=&a=1&a=2&b=boo#test-anchor"): false
$.isUrlExternal("foo"): false
$.isUrlExternal("foo#test-anchor"): false
$.isUrlExternal("foo/"): false
$.isUrlExternal("foo/bar.html?baz=123"): false
$.isUrlExternal("bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("/foo"): false
$.isUrlExternal("/foo/"): false
$.isUrlExternal("/foo/bar.html?baz=123"): false
$.isUrlExternal("/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("https://benalman.com/"): false
$.isUrlExternal("http://www.benalman.com/"): false
$.isUrlExternal("http://www.benalman.com/foo#test-anchor"): false
$.isUrlExternal("http://www.benalman.com/foo/#test-anchor"): false
$.isUrlExternal("https://benalman.com/foo/bar.html"): false
$.isUrlExternal("https://benalman.com/foo/bar.html?baz=123"): false
$.isUrlExternal("https://benalman.com/foo/bar.html?baz=123&test="): false
$.isUrlExternal("https://benalman.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("https://benalman.com:81/"): true
$.isUrlExternal("http://foo.benalman.com/"): false
$.isUrlExternal("http://foo.benalman.com/bar.html?test=&a=1&a=2&b=boo"): false
$.isUrlExternal("https://foo.benalman.com/"): false
$.isUrlExternal("http://bar.benalman.com/"): true
$.isUrlExternal("https://benalman.com/"): false
$.isUrlExternal("https://www.benalman.com/"): false
$.isUrlExternal("https://google.com/"): true
$.isUrlExternal("https://google.com/foo/bar.html?baz=123&test="): true
$.isUrlExternal("https://google.com/bar.html?test=&a=1&a=2&b=boo"): true
$.isUrlExternal("#test-anchor"): undefined
$.isUrlExternal("mailto:spam@benalman.com"): undefined
$.isUrlExternal("javascript:alert('hello world')"): undefined
$.isUrlExternal("ftp://ftp.example.com/foo/bar"): undefined
$.isUrlExternal("irc://irc.example.com/foo/bar"): undefined
$.isUrlExternal("arbitrary://irc.example.com/foo/bar"): undefined
$.isUrlExternal("#"): undefined
$.isUrlExternal("#foo"): undefined
$.isUrlExternal("#test=&a=1&a=2&b=boo"): undefined
$.isUrlExternal("#baz=123"): undefined