国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

iframe自適應寬度、高度 ie6 7 8,firefox 3.86下測試通過

2019-11-21 00:19:49
字體:
來源:轉載
供稿:網友
廢話不多說,貼上代碼,也算是自己的一個代碼存儲。
復制代碼 代碼如下:

var temp_iframe
var content = document.getElementById('right'); //id為 right的DOM容器中,進行創建iframe和寬高自適應
var c = 0;
function append(filename)
{
var the_iframe = "helpfile" + c;
temp_iframe = document.createElement("iframe");
temp_iframe.src = filename;
temp_iframe.scrolling = "no";
temp_iframe.setAttribute("frameborder", "0");
temp_iframe.id = the_iframe;
temp_iframe.name = the_iframe;
scroll(0, 0);
content.innerHTML = "";
content.appendChild(temp_iframe);
if (document.all)
{
temp_iframe.attachEvent('onload', function()
{
temp_iframe.setAttribute("width", window.frames[the_iframe].document.body.scrollWidth); //自適應寬
temp_iframe.setAttribute("height", window.frames[the_iframe].document.body.scrollHeight); //自適應高
});
}
else
{
temp_iframe.addEventListener('load', function()
{
temp_iframe.setAttribute("width", window.frames[the_iframe].document.body.scrollWidth);
temp_iframe.setAttribute("height", window.frames[the_iframe].document.body.scrollHeight);
}, false);
}
c++;
return false;
}
/*調用方法
把此腳本另存為腳本文件:iframe.js,然后再前臺頁面中調用:
------------------------------------------------------------------------
<a href="index.html" onclick="return append('xxxx.html')" class="li1">
<div id="right"></div>
<script type="text/javascript" src="iframe.js"></script>
------------------------------------------------------------------------
或者 去掉腳本中最后的 return false,前臺:
------------------------------------------------------------------------
<a href="javascript:append('favorite/Favorites.html')" class="li1">
<div id="right"></div>
<script type="text/javascript" src="iframe.js"></script>
------------------------------------------------------------------------
*/

嘿嘿,其中,最后設置自適應寬高的,其實可以提出來成為一個函數來調用。
這個我沒去那么做,有看到文章的朋友,可自行封裝。

其中,還有一些不太方便的,比如我每次建立的iframe必須不同的名字和id,即時刪除原來已經創建的也不行……
還是希望大家多多指教吧。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定远县| 拜城县| 洪泽县| 白沙| 巴楚县| 军事| 渝北区| 新乡市| 南澳县| 武强县| 福州市| 东阿县| 西贡区| 崇礼县| 新乐市| 苗栗市| 威宁| 晋城| 张家川| 得荣县| 蒙阴县| 繁峙县| 渑池县| 永和县| 伊春市| 革吉县| 乌审旗| 阿城市| 江安县| 兴化市| 永修县| 洛宁县| 巴楚县| 湛江市| 云梦县| 长治县| 嵩明县| 奉贤区| 卢龙县| 涟源市| 阳原县|