Created
July 9, 2011 13:50
-
-
Save mala/1073591 to your computer and use it in GitHub Desktop.
jQueryでクロスドメイン読み込みを全般的に禁止する
This file contains 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
// jQueryでクロスドメイン読み込みを全般的に禁止する | |
// Note: 同一ドメインにオープンリダイレクタがないか確認すること | |
(function($){ | |
var gethost = function(url){ | |
var a = document.createElement("a"); | |
a.href = url; | |
return a.host | |
}; | |
var old_beforesend = $.ajaxSettings.beforeSend; | |
$.ajaxSetup({ | |
beforeSend: function(xhr){ | |
if (location.host != gethost(this.url)) return false; | |
if (old_beforesend) { | |
return old_beforesend.apply(this, arguments) | |
} | |
return true | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment