(1).使用<script>構造的request請求可以解決跨域的問題,而使用ifame也可以構造請求不過有時瀏覽器不支持iframe的跨域訪問,所以大家在使用的時候就要根據自己的實際情況去選擇應該使用那一種了
try{
varscript_el=document.createElement("script");
script_el.type="text/javascript";
script_el.src="http://www.baidu.com";
h=document.getElementsByTagName("head")[0];
h.appendChild(script_el);
}
catch(e){
alert(e);
}
(2).其實原理是一樣的,只是換一種方式來寫罷了
document.write('<scripttype="text\/javascript"src="http://www.baidu.com?"'+Math.random()+'><\/script>');