2

I have an iframe opening in my application, I want to open a particular application page (say chat window) from a button inside that iframe but as I need to send some data to that page too, I have to call a function. Iframe have the page hosted on our website. Can we have control from iframe pages to application? Can we launch a mobile app from browser?

I am using jQuery mobile and PhoneGap both latest version. Here is my page and for example I want to go to welcome page or want to open a chat window which is a functionality in my app from inside iframe which is a aspx page:

<div data-role="page" id="page" data-theme='b' data-dom-cache="false" class="demo-page">
    <div data-role="content">
        <iframe id="page-src" src="http://mywebsite/page.aspx" width="100%" height="100%" class="bootstrap-iframe"></iframe>
    </div>
</div>
Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73
Jaya Vishwakarma
  • 1,332
  • 1
  • 18
  • 36

1 Answers1

3

Try this: Call

parent.postMessage('msg','*');

from inside iframe.

you can get this event in your page using-

window.addEventListener('message',function(event) {
   alert(event.data); // call function here
},false);

Can add conditions accordingly data you get from iframe.

  • This will not work as you post a message of type "msg" while you listen to a message of type "message". Those two must match for this to work. – pieroxy Nov 18 '20 at 18:31