我想使用CORS在不同网站的div中加载一个带有javascripts的网站,现在我可以加载网站,但它不会加载javascripts。这是我的代码:
<div id="main"></div>
<script type="text/javascript">
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
} else if (typeof XDomainRequest !== "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var request = createCORSRequest("get", "http://localhost:15266/Widget/MyWebsite.html");
if (request){
request.onreadystatechange = function() {
if (request.readyState === 4) {
if (request.status >= 200 && request.status < 400) {
document.getElementById("main").innerHTML = request.responseText;
} else {
alert("error: " + request.status);
}
}
};
request.send();
}
</script>