www.webdeveloper.com
Results 1 to 3 of 3

Thread: Child to parent messaging within iframes

Hybrid View

  1. #1
    Join Date
    Feb 2014
    Posts
    2

    Child to parent messaging within iframes

    Hello,
    I am trying to postMessage to the parent and can't make it work.
    I tried to manipulate it in many ways, here is the last try, that also doesn't work.
    Will appreciate any kind of help.
    Thanks

    This is the receiver:
    Code:
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
       <title>receiver</title>
    </head>
    <body>
    
    <iframe id="receiver">
       <script type="text/javascript">
       	  window.addEventListener('message', receiveMessage, false);
    	  
           function receiveMessage(evt) 
           {
               alert("got message: " + evt.data);
           }
    
       </script>
       
          <iframe id="sender" src="./sender.html"></iframe>
    
    
    </iframe>
    
    <div>Please wait..</div>
    </body>
    </html>
    And here is the sender:
    Code:
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title>sender</title>
    </head>
    <body>
    <div>sender..</div>
    
        <script type="text/javascript">
            var id= "12345667";
    		var o = parent.getElementById('receiver');
            o.postMessage(id, '*');
    
        </script>
    </body>
    </html>
    \

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,123
    I responded to a thread just one above yours
    http://www.webdeveloper.com/forum/sh...53#post1315453

    Take a look, and view the windows example link that I have posted, there are examples which will allow you to understand most of the aspects of inter window communication (all windows have to be of the same site)
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Feb 2014
    Posts
    2
    I had a look and it seems a bit different.
    I need to use postMessage and receive function.
    furthermore, my inner frame is from another domain (i enable cross site scripting).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles