Created
January 9, 2012 14:17
-
-
Save phloe/1583118 to your computer and use it in GitHub Desktop.
Crossdomain url test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| document.location of the current page tested against a url (string) like: | |
| "pages/page.html" // false | |
| "../pages/page.html" // false | |
| "/pages/page.html" // false | |
| "//foo.bar.com/pages/page.html" // false | |
| "http://foo.bar.com/pages/page.html" // false | |
| "//bar.com/pages/page.html" // true | |
| "https://bar.com/pages/page.html" // true | |
| */ | |
| function isXDomain (url) { | |
| return !( | |
| url.match(/^((\.\.\/)|([^:/]+\/)|(\/[^/]))/) || | |
| (url.match(/^\/\//) || url.indexOf(location.protocol) == 0) && | |
| url.indexOf("//" + location.hostname) > -1 | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Haven't checked about the validity of that URL, however try changing the RE to:
to avoid that dubious condition and see if it fits exactly all your tests/needs.