DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> 在一個js文件裡遠程調用jquery.js會在ie8下的一個奇怪問題
在一個js文件裡遠程調用jquery.js會在ie8下的一個奇怪問題
編輯:關於JavaScript     
復制代碼 代碼如下:
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.jb51.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.jb51.cn" >素材下載</a> & 桦</p>
<p style="font-size:12px;">參考:<a href="http://www.jb51.net" ></a></p>
</body>
</html>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved