-
-
Save adriengibrat/2926596 to your computer and use it in GitHub Desktop.
isSameOrigin
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
Page url: <span id="location"></span> | |
<div> | |
<span class="url">http://fiddle.jshell.net</span> <span>true</span></div> | |
<div><span class="url">http://fiddle.jshell.net:80</span> <span>true</span></div> | |
<div><span class="url">//fiddle.jshell.net</span> <span>true</span></div> | |
<div><span class="url">//fiddle.jshell.net:80</span> <span>true</span></div> | |
<div><span class="url">http://fiddle.jshell.net:81</span> <span>false</span></div> | |
<div><span class="url">https://fiddle.jshell.net</span> <span>false</span></div> |
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
function isSameOrigin (url) { | |
with (isSameOrigin.a || (isSameOrigin.a = document.createElement('a'))) | |
return href = url, host = host, !href.indexOf(/^.*?\w\//.exec(location)[0]) | |
} | |
jQuery( function ( $ ) { | |
$( '#location' ).html( | |
'<br> href: ' + location.href + | |
'<br> host: ' + location.host + | |
'<br> port: ' + location.port | |
); | |
$( '.url' ).each( function () { | |
var self = $( this ) | |
, log = self.next(); | |
self.css( 'color', | |
log.text() | |
== | |
isSameOrigin( | |
self.text() | |
) + '' | |
? 'green' : 'red' | |
); | |
log.html( | |
'<br> href: ' + isSameOrigin.a.href + | |
'<br> host: ' + isSameOrigin.a.host + | |
'<br> port: ' + isSameOrigin.a.port | |
); | |
} ); | |
} ); |
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
name: isSameOrigin tests | |
description: Test page to check a 140 bytes cross browser isSameOrigin function | |
# See: http://jsfiddle.net/gh/gist/jquery/1.7/2926596/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment