Solved

document.readyState = 'complete' giving an error

Posted on 2003-11-07
10
1,583 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
Comment Utility
what about using setTimeout onload and setting to reload the parent window after n seconds
0
 

Author Comment

by:prashanth9
Comment Utility
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
Comment Utility
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
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
might try this

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

Expert Comment

by:jaysolomon
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:prashanth9
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now