这样的脚本你在ie8下调用,在ie8地址栏下按下回车后调用jquery的对像、方法什么的没有问题,但是刷新之后就有问题。就是刷新之后无论怎样你要在地址栏按一下回车。
Demo:跨域 <script> <BR>function include(path){ <BR>var a=document.createElement("script"); <BR>a.type = "text/javascript"; <BR>a.src=path; <BR>//if (a.readStatus == 200) { <BR>var head=document.getElementsByTagName("head")[0]; <BR>head.appendChild(a); <BR>//} <BR>} <BR>include("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js") <BR></script>
<script> <BR>$(function(){ <BR>function sendData(url, callback){ <BR>if(!url || typeof url !== 'string'){ <BR>return; <BR>} <BR>url += (url.indexOf('?') > 0 ? '&' : '?') + 'windowname=true'; <BR>var frame = $('<iframe style="display:none;">').appendTo("body"); <BR>var state = 0; <BR>var clear = function(){ <BR>try{ <BR>frame[0].contentWindow.document.write('');//清空iframe的内容 <BR>frame[0].contentWindow.close();//避免iframe内存泄漏 <BR>frame.remove();//删除iframe <BR>}catch(e){} <BR>}; <BR>var getData = function(){ <BR>try{ <BR>var data = frame[0].contentWindow.name; <BR>}catch(e){} <BR>clear(); <BR>if(callback && typeof callback === 'function'){ <BR>callback(data); <BR>} <BR>}; <BR>frame.bind('load', function(){ <BR>if(state === 1){ <BR>getData(); <BR>} else if(state === 0){ <BR>state = 1; <BR>frame[0].contentWindow.location = "none.html"; <BR>} <BR>}); <BR>frame[0].src = url; <BR>} <BR>//应用: <BR>var testurl = 'http://www.jb51.cn/test.html'; <BR>$("button").click(function(){ <BR>sendData( testurl ,function(result){ <BR>var fishDiv = $("#oldFish"); <BR>fishDiv.html( "你获取的数据是:"+result ); <BR>}) <BR>}) <BR>}) <BR></script>
远程加载数据
Dev By 素材下载 & 桦
参考:脚本之家