在一个js文件里远程调用jquery.js会在ie8下的一个奇怪问题

复制代码 代码如下:

  function include(path){

  var a=document.createElement("script");

  a.type = "text/javascript";

  a.src=path;

  var head=document.getElementsByTagName("head")[0];

  head.appendChild(a);

  }

  include("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js")

  这样的脚本你在ie8下调用,在ie8地址栏下按下回车后调用jquery的对像、方法什么的没有问题,但是刷新之后就有问题。就是刷新之后无论怎样你要在地址栏按一下回车。

  在火狐下是没有问题的。附一个window.name的html脚本,大家可以测试一下:

  

复制代码 代码如下:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>

  <title>Demo:跨域</title>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <script>

  function include(path){

  var a=document.createElement("script");

  a.type = "text/javascript";

  a.src=path;

  //if (a.readStatus == 200) {

  var head=document.getElementsByTagName("head")[0];

  head.appendChild(a);

  //}

  }

  include("http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js")

  </script>

  <script>

  $(function(){

  function sendData(url, callback){

  if(!url || typeof url !== 'string'){

  return;

  }

  url += (url.indexOf('?') > 0 ? '&' : '?') + 'windowname=true';

  var frame = $('<iframe style="display:none;"></iframe>').appendTo("body");

  var state = 0;

  var clear = function(){

  try{

  frame[0].contentWindow.document.write('');//清空iframe的内容

  frame[0].contentWindow.close();//避免iframe内存泄漏

  frame.remove();//删除iframe

  }catch(e){}

  };

  var getData = function(){

  try{

  var data = frame[0].contentWindow.name;

  }catch(e){}

  clear();

  if(callback && typeof callback === 'function'){

  callback(data);

  }

  };

  frame.bind('load', function(){

  if(state === 1){

  getData();

  } else if(state === 0){

  state = 1;

  frame[0].contentWindow.location = "none.html";

  }

  });

  frame[0].src = url;

  }

  //应用:

  var testurl = 'http://www..cn/test.html';

  $("button").click(function(){

  sendData( testurl ,function(result){

  var fishDiv = $("#oldFish");

  fishDiv.html( "你获取的数据是:"+result );

  })

  })

  })

  </script>

  </head>

  <body>

  <button>远程加载数据</button>

  <div id="oldFish"></div>

  <p style="font-size:12px;">Dev By <a href="http://www..cn" >素材下载</a> & 桦</p>

  <p style="font-size:12px;">参考:<a href="http://www.glzy8.com" >管理资源吧</a></p>

  </body>

  </html>