EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Pierre on June 01, 2018, 05:38:17 AM



Title: [SOLVED] Access from iframe
Post by: Pierre on June 01, 2018, 05:38:17 AM
Hello
I have main document and iframe inside main document.
How to access some EasyUI component from iframe if component is stored on main document, please?
Thank you.


Title: Re: Access from iframe
Post by: Pierre on June 02, 2018, 12:54:08 AM
Maybe I have not explained correctly so I created 2 files:
- please run "iframe.htm" and click on button. After that, I need to see panel opened on "main.htm"
How to do that, please?
Thank you for your help.


Title: Re: Access from iframe
Post by: Pierre on June 02, 2018, 11:11:58 PM
Anybody, please?


Title: Re: Access from iframe
Post by: jarry on June 03, 2018, 12:54:12 AM
You can't create panel through the iframe but you can post message to the iframe to create it. Some code looks like this:

iframe.htm
Code:
var _panel = ''+

'<div id="p" class="easyui-panel" closed="true" title="Panel" style="width:50%;height:200px;padding:10px;">'+

'  Some sample text inside Panel.'+

'</div>';
var data = {
  act: 'createpanel',
  msg: _panel
}
$('iframe')[0].contentWindow.postMessage(data,'*');

main.htm
Code:
window.addEventListener('message', function(e){
  $('#myDiv').html(e.data.msg);
  $.parser.parse($('#myDiv'))
  $('#p').panel('open')
}, false)


Title: Re: Access from iframe
Post by: Pierre on June 03, 2018, 01:25:43 AM
Awesome Jarry, even this is not EasyUI support, you helped with that, too, so thank you from my heart!