Skip to content

Instantly share code, notes, and snippets.

@mala
Created July 9, 2011 13:50
Show Gist options
  • Save mala/1073591 to your computer and use it in GitHub Desktop.
Save mala/1073591 to your computer and use it in GitHub Desktop.
jQueryでクロスドメイン読み込みを全般的に禁止する
// 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