最近做項目中用到了iframe,子頁面更改父頁面的高度,經過九九八十一難,找到了解決的辦法。 $(window).load(function() { var h=$(document).height(); var ifHeight = $(window.top.document).find ...
function setIframeHeight id try var iframe document.getElementById id if iframe.attachEvent iframe.attachEvent onload , function iframe.height iframe.contentWindow.document.documentElement.scrollHeig ...
2019-09-16 14:30 0 2444 推薦指數:
最近做項目中用到了iframe,子頁面更改父頁面的高度,經過九九八十一難,找到了解決的辦法。 $(window).load(function() { var h=$(document).height(); var ifHeight = $(window.top.document).find ...
子頁面a.php代碼如下: 父頁面p.php代碼如下: 父頁面JavaScript代碼如下: ...
問題的緣由 產品有個評論列表引用的是個iframe,高度不固定於是引發這個總結。 方法1:父級頁面獲取子級頁面的高度 給元素設置高度 這方法是用在父級頁面里的,通過獲取子級頁面的高度給iframe設置高度 涉及了一些兼容問題: IE用attachEvent | 3C用onload來判斷子 ...
javascript獲取iframe框架中,加載的頁面document對象 因為瀏覽器安全限制,對跨域訪問的頁面,其document對象無法讀取、設置屬性 function getDocument(iframe) { var Doc ...
由於瀏覽器安全原因以下的contentDocument 和contentWindow 對象必須起一個頁面服務(通過域名或ip地址來訪問)並且得保證父頁面與子頁面是在同一域名下,不然是會報錯的 contentDocument 可以獲得iframe子窗口的document對象,兼容ie8+ ...
父頁HTML: <iframe id="mainframe" name="mainframe" style="width:100%;" marginheight="0" marginwidth="0" onLoad="iFrameHeight ...
用iframe嵌套頁面時,如果父頁面要獲取子頁面里面的內容,可以使用contentWindow或者contentDocument,其區別如下: 1、contentWindow 這是個只讀屬性,返回指定的iframe的窗口對象。它雖然不是標准的一部分,但各個主流瀏覽器都支持 ...