![](/img/trans.png)
[英]Javascript: Date() function does not fully work in Google Chrome
[英]Javascript resize function for iframes does not work in google chrome
我使用了一個我在stackoverflow上找到的javascript resize函數,它適用於IE和FF。 但是,在Google Chrome中,它只能調整比前一個更大的iframe。 如果必須調整較小的iframe,則需要相同的高度並增加30px。
我認為它與檢索scrollHeight有關,但我不知道如何修復它。
我已經嘗試使用超時,因為我讀到的地方可能有所幫助,但事實並非如此。
這是相關的代碼:
function autoResize(id){
var newheight;
if(document.getElementById)
{
newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
newheight=newheight+30;
}
document.getElementById(id).height = (newheight) + "px";
}
<iframe src="<?php echo "$LC"; ?>/home.html" name="iframe" id="iframe" width="435px" height="10px" scrolling="no" frameborder="0" style="margin-left:-10px;padding-bottom:20px;" onLoad="setTimeout(autoResize('iframe'),250);";">
編輯:通過將功能更改為解決它
function autoResize(id) {
document.getElementById(id).height = document.getElementById(id).contentDocument.documentElement.scrollHeight+15; //Chrome
document.getElementById(id).height = document.getElementById(id).contentWindow.document.body.scrollHeight+15; //FF, IE
}
function autoResize(id) {
document.getElementById(id).height = document.getElementById(id).contentDocument.documentElement.scrollHeight+15; //Chrome
document.getElementById(id).height = document.getElementById(id).contentWindow.document.body.scrollHeight+15; //FF, IE
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.