Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

document.readyState = 'complete' giving an error

Posted on 2003-11-07
10
1,599 Views
Last Modified: 2007-12-19
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..
0
Comment
Question by:prashanth9
  • 4
  • 3
  • 3
10 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9703589
what about using setTimeout onload and setting to reload the parent window after n seconds
0
 

Author Comment

by:prashanth9
ID: 9703658
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();
}
0
 
LVL 25

Expert Comment

by:devic
ID: 9703689
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);

      }
}
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:jaysolomon
ID: 9703701
might try this

if (_wPrint.document.readyState != "interactive") {
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9703737
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();
}
0
 

Author Comment

by:prashanth9
ID: 9703775
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....

0
 
LVL 25

Accepted Solution

by:
devic earned 100 total points
ID: 9703819
ok error is event too ;)

=-=======================
function checkPage()
{
      try
      {
            if (_wPrint.document.readyState != "complete")
            {
                  alert("Still WAITING...Not Loaded");
                  setTimeout('checkPage()',100);
      
            }
      }
      catch(e)
      {
            //This following function has the logic to reload the parent.....
            reload_parent();
      }
}
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9703902
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
0
 

Author Comment

by:prashanth9
ID: 9704041
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 !!!!
0
 
LVL 25

Expert Comment

by:devic
ID: 9704096
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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question