1. 程式人生 > >iframe內容未知,高度可預測

iframe內容未知,高度可預測

<iframe src="backtop.html" frameborder="0" scrolling="no" id="external-frame" onload="setIframeHeight(this)"></iframe>

          <script type="text/javascript">
                /*
                * When the iframe is on a different subdomain, uncomment the following line
                * and change "example.com" to your domain.
                */
                function setIframeHeight(iframe) {
                    if (iframe) {
                        var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
                        if (iframeWin.document.body) {
                            iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
                        }
                    }
                };               window.onload = function () {
                  setIframeHeight(document.getElementById('mainFrame'));
              };
      </script>