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
LVL 4
NHBFighterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

COBOLdinosaurCommented:
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&
0
COBOLdinosaurCommented:
Would using the onload event of the body tag not give you what you need?

Cd&
0
GwynforWebCommented:
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>


0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GwynforWebCommented:
adding frameborder="0" to the iframe tag will take the border off as well
0
NHBFighterAuthor Commented:
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.

0
NHBFighterAuthor Commented:
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.
0
NHBFighterAuthor Commented:
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.
0
GwynforWebCommented:
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>
0
GwynforWebCommented:
'EMBED src'   not   'EMBEDsrc'
0
NHBFighterAuthor Commented:
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
0
GwynforWebCommented:
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>
0
GwynforWebCommented:
hmm, perhaps it does not the iframe still loads first.
0
GwynforWebCommented:
..then again it seems to work now, I am going nuts,:(
0
GwynforWebCommented:
you are still going to have timing problems as the window will close before the actual print is fired, the printDialog is not modal.
0
NHBFighterAuthor Commented:
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
0
wzd3Commented:
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.
0
NHBFighterAuthor Commented:
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
0
robotman757Commented:
so far this has worked every time i try it:

<html>
<script language="javascript">
function testme()
{
alert("testing");
document.getElementById('embedObj').printWithDialog();
}
</script>
<body onbeforeunload="testme()">
<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"></IFRAME>
</body>
</html>
<script language="javascript">
for(var i = 0; i < 30000; i++){}
window.opener="_self";
window.close();
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hallvorsCommented:
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.
0
GwynforWebCommented:
This idea does not need a popup and has not failed on me once

<script>
flag=0
function printIt(){
   setTimeout('document.PDF.printWithDialog()',750)
}

function load(){
 if  (flag==1){
   document.PDF.src="http://www.copyright.gov/legislation/dmca.pdf"
   document.getElementById('i1').src="http://www.copyright.gov/legislation/dmca.pdf"
 }
 if (flag >1) printIt()
}
</script>

<body>
<IFRAME id="i1" onload="if (flag>0){printIt()};flag+=1"  height="0" width="0"></IFRAME>
<object id="PDF" style="LEFT: 0px; TOP: 0px" height="0" width="0" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" VIEWASTEXT>
</object>

<a href="#" onclick="load();return false">Print the pdf</a>
</body>

0
NHBFighterAuthor Commented:
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
0
robotman757Commented:
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!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.