-1

There are so many posts for this. I have gone through all of those, yet no luck. I'm struggling for so long (Onload event is not working ). I dint find any solution.

I have tried.. 1.

<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
 <script type="text/javascript">
document.getElementById('pdfcontent').onload = function() {
   alert("working");
}

</script>
</head>
<body >
<div id="loadingpdf">Loading pdf</div>
<iframe src="http://prodevapp.com/ArmyPublicRelation/pdf/royalthaiarmynews/news_20141103173559.pdf" id="pdfcontent" />
</body>
</html>

2.

$.ajaxSetup(
            {
                cache: false,
                beforeSend: function() {
                    $('object').hide();
                    $('#loadingpdf').show();
                },
                complete: function() {
                    $('#loadingpdf').hide();
                    $('object').show();
                },
                success: function() {
                    $('#loadingpdf').hide();
                    $('object').show();
                }
            });
            var $container = $('object');
            $container.load(function(){
        alert("Image loaded.");});

3.

         <body >
    <script>
function my_code(){
alert(" working");
}
var iframe = document.createElement("iframe");    
iframe.src = "http://prodevapp.com/ArmyPublicRelation/pdf/royalthaiarmynews/news_20141103173559.pdf";
document.body.appendChild(iframe);
iframe.onload=my_code;
</script>
</body>

4.

$("iframe").on('load', function() {
  alert('Image Loaded'); 
}).each(function() {
  if(this.complete) $(this).load();
});  //this worked one time but later it doesn't work it seems some cache problem. 

How to fix this?

vidhya
  • 439
  • 5
  • 20

2 Answers2

0
  1. Duplicate of getElementById() returns null even though the element exists and you are also missing the end tag for the <iframe>.
  2. You are using an iframe, not Ajax, so watching for Ajax things won't work
  3. You try to use the iframe variable before you assign a value to it.
    • After editing it - you try to use a function before it has been defined. While functions are hoisted, they aren't hoisted from later scripts.
    • After editing it again - it works.
  4. Also a duplicate of getElementById() returns null even though the element exists
Community
  • 1
  • 1
Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
  • Shall i know in 1. where am missing the end tag for ` and for 3. I changed my code and tried but no luck i have updated my post . – vidhya Feb 18 '15 at 11:52
  • @VidhyaRaju — You see where you don't have ``? That's where you are missing the end tag. – Quentin Feb 18 '15 at 11:54
  • but am using `/>` at the end. – vidhya Feb 18 '15 at 11:57
  • I tried with some code change in 3 as you mentioned but still problem exists. I have updated. – vidhya Feb 18 '15 at 12:04
  • @VidhyaRaju — Using `/>` at the end is not the same as putting an end tag. It just means you're addicted to XML. HTML is not XML. – Quentin Feb 18 '15 at 12:13
  • The latest version of your 3rd code sample works: http://jsbin.com/duxapudoce/2/edit?html,output – Quentin Feb 18 '15 at 12:14
  • Can you pls have a look at this [quote](http://quotequads.co.in/erase.php). I tried the same code, but it doesn't work. Why is it so? – vidhya Feb 18 '15 at 12:19
  • In my sys, I tried in both mozilla and chrome it doesn't work. Now I tried from other system it works fine. What would be problem? – vidhya Feb 18 '15 at 12:27
0

You might find help here

The selected answer on this thread, interestingly, suggests you cant track a pdf load.

Community
  • 1
  • 1