Skip to content

Instantly share code, notes, and snippets.

@kohashi
Last active February 24, 2017 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohashi/1ada13a377fdf3d27367f590fd8e0e3e to your computer and use it in GitHub Desktop.
Save kohashi/1ada13a377fdf3d27367f590fd8e0e3e to your computer and use it in GitHub Desktop.
別オリジンのscriptファイルが、scriptタグを動的に生成できるかのテストだよ
alert("作られたscriptタグからこんにちわ")
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://jsonplaceholder.typicode.com/posts");
xhr.onreadystatechange = function(/* evt */) {
console.log(xhr)
if (xhr.readyState == 4) {
if (xhr.status == 200) {
that.success(xhr.responseText);
} else {
that.error();
}
}
};
xhr.ontimeout = function() {
console.log("xhr timeout")
};
xhr.timeout = 3000;
xhr.send();
var body = document.getElementsByTagName("body")[0];
var url = 'https://rawgit.com/kohashi/1ada13a377fdf3d27367f590fd8e0e3e/raw/981ea86ccedd37218317978014de34282ece871c/alert.js';
var scriptTag = document.createElement('script');
scriptTag.setAttribute("type", "text/javascript");
scriptTag.src=url + "?" + (new Date().getTime());
document.body.appendChild(scriptTag);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment