IFRAME cross-domain access to Parent frame JS method

Source: Internet
Author: User

IFRAME cross-domain access to Parent frame JS method

Conditions

1. Not under the same primary domain

2.iframe calling the parent frame method

Environment description

The parent frame has the option to open the tab page, but the child pages are embedded in other system pages and the tab page is also opened.

Method description

The principle is to use the calling method by embedding the parent frame page with a child page

Parent Frame Bridge connecting page

1 @{2Viewbag.title ="cross-domain Bridge connection";3Layout ="~/views/shared/_layoutcenter.cshtml";4 }5 6 @section scripts{7<script>8Parent.parent.DomainAddtabs ("@ViewBag. Url","@ViewBag. Name");//Execute main function9</script>Ten}

Subsystem JS method

1 /*2 cross-domain issues3 */4 ; (function ($) {5 $.extend ({6 senddomain:function (OPT, callback) {7             varDefaults = {8Wmsurl:'#',9Icon'icon-house_in',//iconsTenTitle'title', OneSapurl:'#' A             }; -             varopts =$.extend (defaults, opt); -  the             Try { -                 varParent =window.parent; -                 varURL =Opts.wmsurl; -                 varicon ="icon"+Opts.icon; + window.parent.addTab (opts.title, URL, icon); -}Catch(e) { +                 varURL =Opts.wmsurl; A $.execmain (URL, opts.title, opts.sapurl); at             } -             if(callback) { - callback (); -             } -         }, -         //EXEC main function in execmain:function (URL, name, Mainurl) { -             if(typeof(exec_obj) = ='undefined') { toExec_obj = Document.createelement ('iframe'); +Exec_obj.name ='Tmp_frame'; -EXEC_OBJ.SRC = Mainurl +'? url='+ URL +'&name='+name; theExec_obj.style.display ='None'; * Document.body.appendChild (exec_obj); $}Else {Panax NotoginsengEXEC_OBJ.SRC = Mainurl +'? url='+ URL +'&name='+ name +'&'+math.random (); -             } the         } +     }); A}) (JQuery);

Complete.

IFRAME cross-domain access to Parent frame JS method

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.