Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set Iframe height by JavaScript

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "JavaScript how to set Iframe height", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "JavaScript how to set Iframe height" article.

Sometimes you may need to embed Iframe in a web page, and the control of Iframe can not be fixed, so you can automatically set the height according to the content in Iframe. Add an onload event to the Iframe tag of HTML, which calculates the setting height when the Iframe page is loaded.

Function SetIFrameHeight (iFrameId) {

If (iFrameId = "") {return;}

Var Sys = {}

Var ua = navigator.userAgent.toLowerCase ()

Var s

(s = ua.match (/ msie ([\ d.] +) /)? Sys.ie = s [1]: 0

Var pTar = null

If (document.getElementById) {

PTar = document.getElementById (iFrameId)

} else {

Eval ('pTar=' + iFrameId +';')

}

PTar.style.display = "block"

If (Sys.ie) {

If (Sys.ie = = '9.0') {

PTar.height = pTar.contentWindow.document.body.offsetHeight + 15 + "px"

PTar.width = pTar.contentWindow.document.body.scrollWidth + "px"

} else if (Sys.ie = = '8.0') {

PTar.height = pTar.Document.body.offsetHeight + 25 + "px"

PTar.width = pTar.Document.body.scrollWidth + "px"

} else {

PTar.height = pTar.Document.body.scrollHeight + 25 + "px"

PTar.width = pTar.Document.body.scrollWidth + "px"

}

}

}

The parameter is the id input of the Iframe, and it is no problem to pass the IE8 test temporarily.

The above is about the content of this article on "how to set the Iframe height of JavaScript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report