兼容主流浏览器的 Iframe 自适应高度,js脚本如下:
//iframe 高度自适应
function iframeAutoFit(iframeObj) {
setTimeout(function () {
if (!iframeObj) return;
iframeObj.height = (iframeObj.Document ? iframeObj.Document.body.scrollHeight : iframeObj.contentDocument.body.offsetHeight);
}, 200);
}<span style=\"font-family: Arial, Helvetica, sans-serif;\"> </span>
调用方法:
<iframe id=\"HQRight\" name=\"HQRight\" onload=\"javascript:iframeAutoFit(this);\"
height=\"235px;\" width=\"770px\" frameborder=\"0\" scrolling=\"no\"
src=\"Market/HQData_page.aspx?t=tjs\"></iframe>
扩展:
//动态添加样式
function addSheetFile(obj, path) {
if (obj == undefined || obj == null)
obj = document;
var fileref = obj.createElement(\"link\")
fileref.rel = \"stylesheet\";
fileref.type = \"text/css\";
fileref.href = path;
fileref.media = \"screen\";
var headobj = obj.getElementsByTagName(\'head\')[0];
headobj.appendChild(fileref);
}
本文地址:https://www.stayed.cn/item/3833
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我