Link to home
Start Free TrialLog in
Avatar of prashanth9
prashanth9

asked on

document.readyState = 'complete' giving an error

Hello guys,

I am trying to open a popup window from my page using window.open and in the child window, I am checking the document.readyState property to see if it is complete (checking to see if child completely loaded) and if it is, I want to reload the parent window since I update some values in the db from my child window.

Although the onLoad function does the same thing, when I tried using the onLoad function of the child window to see if it is loaded fully, the onLoad function is not getting triggered properly. This maybe because I am receiving a PDF stream to the child from the backend.

But, when I use the document.readyState property, I always get an "Access Denied" error in Javascript when the document is fully loaded.....I think I am almost there but this error is killing me....Is there any way I can get around this problem ??

If my question is not clear, please let me know and I will clarify..
Avatar of jaysolomon
jaysolomon

what about using setTimeout onload and setting to reload the parent window after n seconds
Avatar of prashanth9

ASKER

I have tried using the setTimeOut function but I never know how long it takes for the child to get loaded - sometime it is quick and sometimes it takes longer...So, it doesnt work....

Here is the code that I have :
In the code below, _wPrint represents the child window.....
var _wPrint  = window.open('', 'some name);
--------------------------------------
function checkPage() {
  var loadedPage = false;
  if (_wPrint.document.readyState == "loading") {
      alert("Still WAITING...Not Loaded");
        setTimeout('checkPage()',100);
  } else {
                //This following function has the logic to reload the parent.....
                reload_parent();
}
Avatar of devic
try this:
==========================
function checkPage()
{
      var loadedPage = false;
      if (_wPrint.document.readyState == "complete")
      {
            //This following function has the logic to reload the parent.....
            reload_parent();
      }
      else
      {
            alert("Still WAITING...Not Loaded");
            setTimeout('checkPage()',3000);

      }
}
might try this

if (_wPrint.document.readyState != "interactive") {
sorry clicked to soon i guess

if (_wPrint.document.readyState != "interactive") {
alert("Still WAITING...Not Loaded");
       setTimeout('checkPage()',100);
  } else {
                //This following function has the logic to reload the parent.....
                reload_parent();
}
Devic,

I tried the option you gave me earlier but it wouldnt work..I keep getting the alert as long as the page is not loaded but once it is loaded, or when the document.readyState is complete, I immediately get the "Access is Denied" error.....

Am I missing something ???

JaySolomon,

I tried your option too....Doesnt work...I get the same error....

ASKER CERTIFIED SOLUTION
Avatar of devic
devic
Flag of Germany image

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
if devics does not work then do this to test


in the pop up page

<script>
alert(document.readyState);
</script>

To see what it says when its loading
Thanks Devic..That was COOOOOOOOOOOOOOL.....I have been breaking my head with this problem for a day now...

It worked like a charm but I would have been much happier if I could do it the normal way instead of catching an exception and reloading the parent in the exception....

Btw, can you please tell me if this logic works in IE and netscape and what versions if possible....Thanks for the help !!!!
i don't support old browsers :)

i have only last versions, and can not help ;(

only info from the book:

Part of the try ... catch ...finally error-handling mechanism.

Availability:
ECMAScript edition – 3
JavaScript – 1.5
JScript – 5.0
Internet Explorer – 5.0
Netscape – 6.0