www.b.com 下的data.html 提供數(shù)據(jù)
www.a.com 下的proxy.html 代理文件,與a.html同一域下,一般為空html文件。
www.b.com下的data.html如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
//添加需要傳遞的數(shù)據(jù),大小一般為2M,IE和firefox下可以大至32M左右
window.name = '[{"name":"test1"},{"name":"test2"}]';
</script>
</body>
</html>
www.a.com下的proxy.html如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <!-- 空的html文件 --> </body> </html>
www.a.com下的a.html如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 用于引用www.b.com/data.html文件 -->
<iframe id="iframe" src=""></iframe>
<!-- 顯示獲取到的數(shù)據(jù) -->
<p id="data"></p>
<script type="text/javascript" src="./jquery.js"></script>
<script type="text/javascript">
var ifr = document.getElementById("iframe");
ifr.src = "http://www.b.com/data.html";
if (ifr.attachEvent) {
ifr.attachEvent("onload", loadfunc);
} else {
ifr.onload = loadfunc;
}
var state = 0;
function loadfunc() {
if(state == 0) {
state = 1;
ifr.contentWindow.location = "http://www.a.com/proxy.html";
} else {
var data = ifr.contentWindow.name;
$.each($.parseJSON(data), function(i, v) {
$("#data").append(v.name);
});
//銷毀iframe,保證安全
ifr.contentWindow.document.write("");
ifr.contentWindow.close();
document.body.removeChild(ifr);
}
}
</script>
</body>
</html>
相關視頻推薦:PHP編程從入門到精通
更多關于云服務器,域名注冊,虛擬主機的問題,請訪問西部數(shù)碼官網(wǎng):m.ps-sw.cn