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