0

I am trying to get this function to build the data I give it and display it in my IFRAME. I just cant get it to display anything. Based off this code, any ideas?

function playBlackjack()
{
   var data = "<table border=0 style='margin:auto'>"
   data += "<tr>"
   data += "<td><form><input type="BUTTON" onClick="Javascript:dealCards()" value="Deal > > >"></form></td>"
   data += showCards(0)
   data += "<td><form><input type="BUTTON" onClick="Javascript:hitCard()" value="< < < Hit Me"></form></td>"
   data += "</tr></table> "
   return productarea.document.writeln(data)
   productarea.document.close()
}
Dolbyover
  • 89
  • 1
  • 2
  • 10

1 Answers1

0
  1. Are you sure that you don't have cross-domain problems. You cannot manipulate the contents of a cross-domain iframe.
  2. If it on different domains you can use message passing. For example, if document A contains an iframe element that contains document B, and script in document A calls postMessage() on the Window object of document B, then a message event will be fired on that object, marked as originating from the Window of document A. The script in document A might look like

    var o = document.getElementsByTagName('iframe')[0];
    o.contentWindow.postMessage('Hello world', 'http://b.example.org/');
    

To register an event handler for incoming events, the script would use addEventListener() (or similar mechanisms). For example, the script in document B might look like:

window.addEventListener('message', receiver, false);
function receiver(e) {
  if (e.origin == 'http://example.com') {
    if (e.data == 'Hello world') {
      e.source.postMessage('Hello', e.origin);
    } else {
      alert(e.data);
    }
  }
}

This script first checks the domain is the expected domain, and then looks at the message, which it either displays to the user, or responds to by sending a message back to the document which sent the message in the first place.

via Invoking JavaScript code in an iframe from the parent page

via http://dev.w3.org/html5/postmsg/#web-messaging

Community
  • 1
  • 1
Igor S.
  • 3,332
  • 1
  • 25
  • 33