Last active
February 24, 2017 03:31
-
-
Save kohashi/1ada13a377fdf3d27367f590fd8e0e3e to your computer and use it in GitHub Desktop.
別オリジンのscriptファイルが、scriptタグを動的に生成できるかのテストだよ
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
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(); | |
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
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