Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created October 11, 2010 01:29
Show Gist options
  • Save jfsiii/619808 to your computer and use it in GitHub Desktop.
Save jfsiii/619808 to your computer and use it in GitHub Desktop.
var hasSameOrigin = (function (window, document, undefined) {
var page = document.location,
protocol = page.protocol,
domain = document.domain,
port = page.port ? page.port : '',
sop_string = protocol + '//' + port + domain,
sop_regex = new RegExp('^' + sop_string),
http_regex = /:\/\//,
data_regex = /^data:/,
closure = function (url)
{
var is_local = (!http_regex.test(url)) || data_regex.test(url),
is_same_origin = sop_regex.test(url);
return is_local || is_same_origin;
};
return closure;
})( window, document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment