0

I am requesting for a PDF from server by doing this:

html: '<embed type="application/pdf" width="1500px" height="800px" src="' + src + '"/>'

Now I know it is very easy to add a loading mask to AJAX Request but how about adding it to the above mentioned request. Lets say if I do this:

Ext.loadMask();
html: '<embed type="application/pdf" width="1500px" height="800px" src="' + src + '"/>'
Ext.hideMask();

The hideMask() gets called even before the response is returned from the server.

I tried onload as well like this:

html: '<embed type="application/pdf" width="1500px" height="800px" src="' + src + '" onload=' + console.log("this PDf has been loaded") + '/>' 

But even this gets called even before I see the PDF

Nick Div
  • 5,338
  • 12
  • 65
  • 127

1 Answers1

0

You stated right that in your provided code you have async code executed, because of your request.

What you can do is try to implement a risky event listener that might work, but it is a subject to debate across different browsers.

Something like :

var targetEl = document.getElementByID("target");
targetEl.innerHTML = '<embed id="embeded" type="application/pdf" width="1500px" height="800px" src="' + src + '"/>';
embeded = document.getElementByID("embeded");
embeded.addEventListener("load", function() { Ext.hideMask(); });

But you will definitely not be sure if this will work across all browsers. Better alternative is to use $("#embed").on('load', function() { ... }); - jQuery library.

References:

Community
  • 1
  • 1
drinchev
  • 19,201
  • 4
  • 67
  • 93
  • I tried onload as well like this: html: '' But even this gets called even before I see the PDF – Nick Div Dec 01 '14 at 19:46
  • usually it's very difficult to control what has happened in the embeded tag ( and iframe for that matter ). That's why service providers give their own APIs for giving back some information to the parent DOM element. You can read a bit more for embedding PDFs to your website on [this StackOverflow question](http://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html). – drinchev Dec 01 '14 at 21:25