mmaceachran
mmaceachran

Reputation: 3338

pdf object.messagehandler onMessage not working in IE

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?

Upvotes: 1

Views: 1615

Answers (1)

mmaceachran
mmaceachran

Reputation: 3338

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.

Upvotes: 3

Related Questions