首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

[]控制iframe载入的方法的优化

2012-08-16 
[求助]控制iframe载入的方法的优化这个控制iframe载入的函数有一个问题,就是已经载入后,再次点击那些按钮

[求助]控制iframe载入的方法的优化
这个控制iframe载入的函数有一个问题,就是已经载入后,再次点击那些按钮会重新载入一次,如何让它如果已经载入了再次点击时不要再次载入刷新呢?

HTML code
<!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>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript"><!--var sites = [    "http://www.blueidea.com",    "http://www.google.com",    "http://www.baidu.com"];function load(index){document.getElementsByTagName("iframe")[index]["src"]=sites[index];}//--></script></head><body><iframe style="width: 100%" id="frameContent0" name="frameContent0" frameborder="0" src=""></iframe><iframe style="width: 100%" id="frameContent1" name="frameContent1" frameborder="0" src=""></iframe><iframe style="width: 100%" id="frameContent2" name="frameContent2" frameborder="0" src=""></iframe><input type="button" value="Load BlueIdea" onclick="load(0);" /><input type="button" value="Load Google" onclick="load(1);" /><input type="button" value="Load Baidu" onclick="load(2);" /></body></html>

同时希望加上这个效果提示又该怎么弄呢?因为它用的是var a = document.getElementById("frameContent0"); 的方法,似乎对每一个iframe都要写一个函数,而我一个页面加载的至少三个iframe,所以就很麻烦。。。

HTML code
<!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><style>*{margin:0; padding:0;}</style></head><body> <div id="load" align="center"><img src="http://sc.cnwebshow.com/upimg/allimg/070707/01294420.gif" /> loading...</div> <!-- 首先放一个div,用做loading效果 --><iframe id="frameContent0" name="frameContent0" src="http://www.yahoo.com" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0"></iframe> <!-- src 里面放你想要的网页--><script type="text/javascript"> //<![CDATA[ var a = document.getElementById("frameContent0"); var b = document.getElementById("load"); a.style.display = "none"; //隐藏 b.style.display = "block"; //显示a.onreadystatechange = function() { if (this.readyState=="complete") { // 解释:一个iframe加载完毕的状态是complete,b.innerHTML = "load complete!"; b.style.display = "none"; a.style.display = "block"; } } //]]> </script> </body>


[解决办法]
<iframe name="E" u="http://www.google.com" k="0" src="javascript: void(0)" onload="alert('加载完成')"></iframe>
<button onclick="aa('E')">google</button>

<script defer="">

function aa(o_w)
{
var _z=document.all(o_w);
if (_z.k=='1') { alert('页面已加载'); return; }
_z.k='1';
_z.src=_z.u;
}

</script>

热点排行
Bad Request.