1

In my pdf, in my onOpenAction, I have this js code:

app.alert(this.hostContainer); 
try { 
   this.hostContainer.postMessage(['Hello World']); 
} catch(e) {app.alert(e.message);} 

in my html, I have this code:

function messageFunc(messageArray) {    
    alert("In message Func:"+messageArray);
}

document.getElementById("pdfObject").messageHandler = { onMessage: messageFunc };

In Chrome and FF this works fine, one pdf alert showing a valid hostContainer, and a web browser alert showing the message, Hello World

In IE (11) I get the pdf alert, showing a valid hostContainer, but no browser alert. No alert saying there was an error.

What am I doing wrong?

mmaceachran
  • 3,178
  • 7
  • 53
  • 102

1 Answers1

3

Turns out, that the PDF needs to be loaded in IE before you can set a messageHandler, So I have done this:

function loadListener() {
var pdfObject = document.getElementById("pdfObject");
if(typeof pdfObject.readyState === 'undefined') { // ready state only works for IE, which is good because we only need to do this for IE because IE sucks in the first place
    pdfObject.messageHandler = { onMessage: messageFunc };  
    return;
}
if(pdfObject.readyState==4) {
    pdfObject.messageHandler = { onMessage: messageFunc };
} else {
    setTimeout(loadListener,500);
}
}

This is working across all 3 browsers. Yea.

mmaceachran
  • 3,178
  • 7
  • 53
  • 102
  • PDF needs to to be loaded in any browser before assigning the messageHandler. IE gives a readyState, whereas other browsers do not give anything – Manoj Reddy Mar 30 '15 at 09:19