Link to home
Start Free TrialLog in
Avatar of NHBFighter
NHBFighter

asked on

onload event not firing for embed tag

Hi

I have a simple page:

<html>
<script>
function onloadFunction(){
      alert("function called");
}
</script>
<body >
      <embed  onload="onloadFunction()" src='fileName.pdf'  id = "embedObj"></embed>
</body>
</html>

the onload event is not firing although the pdf is being loaded.
I've tried various ways to set this ie:
<script>
 document.getElementById("embedObj").onload =onloadFunction;
</script>

but it never seems to fire.
The browse I'm using is IE 6.0
Any suggestions?

Thanks
Dave
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

From a source most of us in the Web TAs consider very reliable
http://www.blooberry.com/indexdot/html/tagpages/attributes/onload.htm

"
Microsoft's documentation says it supports the ONLOAD event handler for the APPLET, EMBED, LINK and SCRIPT elements, but I was unable to verify this in direct testing.
"

I think your chances of getting it to work are pretty slim.

Cd&
Would using the onload event of the body tag not give you what you need?

Cd&
the documentation clearly states that the onload should work, however I can not get it to work either. This has the identical effect to what you are trying to achieve.

<script>
function onloadFunction(){
     alert("function called");
}
</script>

<iframe onload="onloadFunction()" height=600 width=800 src="http://www.copyright.gov/legislation/dmca.pdf" id="embedObj"></iframe>


adding frameborder="0" to the iframe tag will take the border off as well
Avatar of NHBFighter
NHBFighter

ASKER

Well what I'm trying to do is get the pdf to load in the embed tag and when its done loading I want to run:
    document.getElementById(embedObj).printWithDialog();
to print the pdf. I tried to load the pdf into an Iframe but then I cant use the printWithDialog(); function.

So... what I want is a page that will open up and print a pdf with out opening the pdf (at least as far as the user sees).
I here is an ugly solution since the embed onload isn't working:
<html>
<script>
function onloadFunction(){
     alert("function called");
}
</script>
<body >
<div style="{display:none}">
     <embed  src='fileName.pdf'  id = "embedObj"></embed>
     <iframe onload="onloadFunction()" src='fileName.pdf'  id = "iframeID"></iframe>
</div>
</body>
</html>

This loads the pdf two times but it works. If anyone has a solution thats better please let me know.
Sorry the  onloadFunction looks like this
function  onloadFunction(){
      document.getElementById('embedObj').printWithDialog();
      window.close();
}

So the window will open (it will give a loading pdf message until it prints) then when the pdf is loaded it will open the print dialog box and close the window.
option 1 :-

<EMBEDsrc="http://www.copyright.gov/legislation/dmca.pdf" id="embedObj" height="0" width="0">
</EMBED>
<IFRAME src="http://www.copyright.gov/legislation/dmca.pdf" height="0"
      width="0" onload="document.getElementById('embedObj').printWithDialog();window.close()">
</IFRAME>

option 2 :-

<body onload="document.getElementById('embedObj').printWithDialog();window.close()">
 <embed src="http://www.copyright.gov/legislation/dmca.pdf" id="embedObj" height="0" width="0"></EMBED>
</body>
'EMBED src'   not   'EMBEDsrc'
I tried putting the onload in the body tag but the problem was it was firing before the pdf was fully loaded into the embed tag so it wasn't working.
This shows that behavior

<body onload="alert('body loaded')">
<div style="{display:none}">
<embed  src='fileName.pdf'></embed>
<iframe  onload="alert('iframe loaded')" src='fileName.pdf' ></iframe>
</div>
</body>

for me the body loaded alert is firing first
this as far as I can see works,

<EMBED src="http://www.copyright.gov/legislation/dmca.pdf" id="embedObj" height="0" width="0">
</EMBED>
<IFRAME src="http://www.copyright.gov/legislation/dmca.pdf" height="0"
      width="0" onload="document.getElementById('embedObj').printWithDialog();window.close()">
</IFRAME>
hmm, perhaps it does not the iframe still loads first.
..then again it seems to work now, I am going nuts,:(
you are still going to have timing problems as the window will close before the actual print is fired, the printDialog is not modal.
What I'm finding is that some times the iframe is loading first and some times the embed is loading first, So the solution isn't so good.  I haven
I haven't run into the other timing issue your referring to yet so far the print as succeded.
I'm still at a loss for how to solve this.

Dave
IE only?  would

<html><head><title></title>
<BODY onload="PDF.printWithDialog()">
<OBJECT id=PDF style="LEFT: 0px; TOP: 0px" height=0 width=0 classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" VIEWASTEXT>
     <PARAM NAME="SRC" VALUE="http://www.copyright.gov/legislation/dmca.pdf">
</OBJECT>
Whatever else goes here
</BODY>
</HTML>

do the job?  It seems to work.
Thanks for all the input but I seem to still be running into the same issue. I want the browser page to open up while the pdf is loading and when the pdf is done loading I want  the printDialog box to pop up and the browser window to close.  The body onload seems to fire before the PDF is loaded completly.
 so I want this onload PDF.printWithDialog(); window.close(); but if the print is called before the PDF is fully loaded there are problems.

Dave
ASKER CERTIFIED SOLUTION
Avatar of robotman757
robotman757

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The eternal question: Why do you want to do this?
If you really want this, try coding it in a way that will degrade nicely in browsers where what you want doesn't work. For instance, the suggestion in the previous message will fail in browsers without the printWithDialog function: a window will open and close again, and the user will not have any way to actually print your PDF. Also remember that some users prefer to have the PDF appear in Acrobat Reader instead of in the browser.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again for the comments

The requirment is that the user should have to click on anything to get the print dialog box.
robotman757  I like your idea but it doesn't seem to work for me. The dialog box does appear but the pdf still isn't being fully loaded into the browse so I receive an error if I try to print it because the window closes before the pdf is loaded.

Dave
Weird. It prints fine for me, but each system is different. Maybe my system is loading things faster. Not really sure about that. Might have to increase the timer length to 100000 but that seems to take forever to me!!