JavaScript realizes automatic height adjustment of iframe and _javascript skills of different main domain names across domains

Source: Internet
Author: User

We all know that JS has a homologous strategy, that is, the main domain name of different nested IFRAME does not allow JS communication.

For example, I have a website where I want to embed the page of its website. Then I can use an IFRAME to refer to the address of a third party website.

But the problem also comes to the height of the iframe is fixed can not be a good fusion with third-party sites, such as third-party sites using waterfall flow plug-ins, to scroll load automatic calculation height, then say cross-domain: IFrame main domain name different Cross-domain method, if the website a.com b.com A Inside put an IFRAME reference B.Com, in this case b.com inside of JS is inaccessible to a.com. JS cross domain must be homologous, is the same main domain name, that swollen mody do?

We can introduce an IFRAME in the B.Com, let's call it a C bar this iframe loads a Web page in a.com. This homology will have the B.Com in the IFRAME in the Web page can and a.com communication. Below as long as the B and C communication, so that C and a communication on the completion of b->a communication, so when the B height changes notify C, let C notice a to the height of the iframe adjustment.
B and C communication, in fact, through the URL address can achieve communication, B.Com iframe set to hide, change the SRC address when C can receive.

Nonsense don't say the code on

A.com/index.html

 
 


B.com/index.html

 


C Proxy file

 <script> var search = window.location.search, Getsearchparam = function (search, key
  {var mc = Search.match (New RegExp (Key + = ([^\&]*))), ret= "";
  MC && mc.length && (ret = mc[0].replace (key + "=", ""));
return ret; },//Parameter H = getsearchparam (search, "H"), Ifmid = Getsearchparam (Search, "Ifmid"), CBN = Getsearchparam (search, "CBN"),// Wide High MH = Getsearchparam (Search, "MH") | | H, isfunction = function (FN) {return!! fn &&!fn.nodename && fn.constructor!= String && fn.constructor!= RegExp && fn.co
 
Nstructor!= Array && (/function/i). Test (fn + "");
    try{if (parent && parent.parent) {IFM = Parent.parent.document.getElementById (Ifmid);
    IFM && MH && (IFM.HEIGHT=MH);
    FN=PARENT.PARENT[CBN];
    Isfunction (FN) && fn.call ();
  Ifm=null;
 
}}catch (ex) {Console.log (ex);} </script> 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.