The cause of the problem
The product has a comment list refers to an IFRAME, the height is not fixed and thus triggered this summary.
Method 1: The parent page gets the height of the child page to set the height of the element
This method is used in the parent page to set the height of the iframe by getting the height of the child page
Some compatibility issues are involved:
IE with attachevent | 3C uses onload to determine whether a child page is loaded or not.
IE with Contentwindow | 3C using Contentdocument to get sub-pages
IE with Document.documentElement.scrollHeight (compatible with IE6 IE7) | 3C get page height with body.scrollheight
functionsetiframeheight (ID) {Try{ variframe =document.getElementById (ID); if(iframe.attachevent) {iframe.attachevent ("OnLoad",function() {iframe.height=Iframe.contentWindow.document.documentElement.scrollHeight; }); return; }Else{iframe.onload=function() {iframe.height=Iframe.contentDocument.body.scrollHeight; }; return; } }Catch(e) {Throw NewError (' Setiframeheight error '); }}
Method 2: Child pages Set the height of the parent page element
This method is used in the child page to set the height of the parent iframe by getting the height of the child page
The child page gets the parent iframe by using parents to set the height for the IFRAME, compatible with Method 1.
The disadvantage is that the IFRAME has a cache when the parent page is brushed, and the demand cleanup cache takes effect.
functionsetparentiframeheight (ID) {Try{ varParentiframe =parent.document.getElementById (ID); if(window.attachevent) {window.attachevent ("OnLoad",function() {parentiframe.height=Document.documentElement.scrollHeight; }); return; }Else{window.onload=function() {parentiframe.height=Document.body.scrollHeight; }; return; } }Catch(e) {Throw NewError (' Setparentiframeheight error '); }}
Cross-domain operations to be aware of
If there is one case for two pages, two subdomains:
Aaa.xxx.com
Bbb.xxx.com
You need to set up two pages as follows:
Document.domain = "xgo.com.cn";
This way the two pages will be able to manipulate each other. That is, the "cross-domain" between the same base domain is implemented.
Cross-domain implementation with Document.domain:
Prerequisites: These two domain names must belong to the same base domain name! And the protocol used, the port must be consistent, or you can not use Document.domain cross-domain
JavaScript prohibits two or more pages of different domains from interacting with one another for security reasons.
Pages in the same domain do not have any problems when working with each other.