Skip to content

Instantly share code, notes, and snippets.

@themorgantown
Forked from janily/iframe
Created June 3, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themorgantown/bde3b0a86a82dd77a7aa7695cc3a8681 to your computer and use it in GitHub Desktop.
Save themorgantown/bde3b0a86a82dd77a7aa7695cc3a8681 to your computer and use it in GitHub Desktop.
iframe
HTML代码:
<iframe id="testIframe" frameborder="0" scrolling="no" src="iframe-page-no-fresh.html" width="100%" height="120"></iframe>
JS代码:
//高度自适应
var iframe = document.getElementById("testIframe");
var iframeHeight = function() {
var hash = window.location.hash.slice(1), h;
if (hash && /height=/.test(hash)) {
h = hash.replace("height=", "");
iframe.height = h;
}
setTimeout(iframeHeight, 2000);
};
iframeHeight();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment