Connecting Tech Pros Worldwide Forums | Help | Site Map

win.document.readystate - how to access

Richard Bell
Guest
 
Posts: n/a
#1: Jul 20 '05
I would like to open a 'child' window win and check it's ready state.
Unfortunately, when I try to do so, I discover that win.document does
not appear accessable from the parent window, see below. Is this by
design or am I doing something wrong.

<HTML>
<HEAD>
<TITLE>Javascript Test</TITLE>
</HEAD>
<SCRIPT language="JavaScript">
var win =
open('http://faqts.com/knowledge-base/community/index.phtml/id/601');
var iq = 0;
var q = "";
q += 'typeof window.document ' + typeof(window.document) + '\n';
q += 'typeof window.document.readystate ' +
typeof(window.document.readyState) + '\n';
q += 'typeof window.addeventListener ' +
typeof(window.addEventListener) + '\n';
q += 'typeof win.document ' + typeof(win.document) + '\n';
q += 'typeof win.document.readystate ' +
typeof(win.document.readyState) + '\n';
q += 'typeof win.addeventListener ' + typeof(win.addEventListener) +
'\n';
</SCRIPT>

<H1>Check access to features</H1>
<BODY onLoad="alert(q)">

</BODY>
</HTML>

Michael Winter
Guest
 
Posts: n/a
#2: Jul 20 '05

re: win.document.readystate - how to access


On Sat, 14 Feb 2004 17:54:25 GMT, Richard Bell <rbell01824@earthlink.net>
wrote:
[color=blue]
> I would like to open a 'child' window win and check it's ready state.
> Unfortunately, when I try to do so, I discover that win.document does
> not appear accessable from the parent window, see below. Is this by
> design or am I doing something wrong.[/color]

It depends. If the page in the new window is from a different domain, you
might get an access error due to security restrictions. Also, you do
realise that readyState is a non-standard property and might not work on
all browsers?

At the moment, the problem is that you haven't capitalised the identifier
properly; JavaScript is case-sensitive, remember. You need to access it
with:

winObj.document.readyState (not readystate)

You have this problem with addEventListener in a couple of places: you
write it 'addeventListener'.

Two final comments relate to your HTML.

1) The heading, H1, and script elements are outside of valid blocks. Move
H1 within BODY and SCRIPT within HEAD or BODY, as appropriate.
2) The script element is missing the required type attribute. It should be
written as shown below. Notice that the language attribute (which is
deprecated) is not necessary when "type" is used.

<script type="text/javascript">

Hope that helps,
Mike

--
Michael Winter
M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Richard Bell
Guest
 
Posts: n/a
#3: Jul 20 '05

re: win.document.readystate - how to access


Thanks Mike.

As it happens, the documents are definitively from another domain. As
near as I can tell this means that for an arbitrary URL, there is no
way within Javascript to determine in the new page has completed
loading as there is very restricted access to the child window's
properties and methods. Soooooooooo it seems that Javascript is not
prepared to handle my needs. Pitty, it's really rather neat.

BTW, the case was OK in the typeof where it mattered, but I've fixed
it where you noticed. Rather sloppy of me. As was the HTML.

As you can tell, I don't normally hang out here. I did a fair bit of
checking in the FAQ, newsgroup archives, etc. and found LOTS of bogus
examples/advice/... . It finially drove me to the example code I sent.
It might be worthwhile if this issue were dealt with in the FAQ as, at
least in my research, it seemed to come up fairly often.

Thanks again.

On Sat, 14 Feb 2004 18:08:45 GMT, Michael Winter
<M.Winter@blueyonder.co.invalid> wrote:
[color=blue]
>On Sat, 14 Feb 2004 17:54:25 GMT, Richard Bell <rbell01824@earthlink.net>
>wrote:
>[color=green]
>> I would like to open a 'child' window win and check it's ready state.
>> Unfortunately, when I try to do so, I discover that win.document does
>> not appear accessable from the parent window, see below. Is this by
>> design or am I doing something wrong.[/color]
>
>It depends. If the page in the new window is from a different domain, you
>might get an access error due to security restrictions. Also, you do
>realise that readyState is a non-standard property and might not work on
>all browsers?
>
>At the moment, the problem is that you haven't capitalised the identifier
>properly; JavaScript is case-sensitive, remember. You need to access it
>with:
>
> winObj.document.readyState (not readystate)
>
>You have this problem with addEventListener in a couple of places: you
>write it 'addeventListener'.
>
>Two final comments relate to your HTML.
>
>1) The heading, H1, and script elements are outside of valid blocks. Move
>H1 within BODY and SCRIPT within HEAD or BODY, as appropriate.
>2) The script element is missing the required type attribute. It should be
>written as shown below. Notice that the language attribute (which is
>deprecated) is not necessary when "type" is used.
>
> <script type="text/javascript">
>
>Hope that helps,
>Mike[/color]

Richard Bell
Guest
 
Posts: n/a
#4: Jul 20 '05

re: win.document.readystate - how to access



Mike,

I should also have mentioned that some of the 'solutions' I found
suggested that frames made a difference. Of course, they do not.


On Sat, 14 Feb 2004 18:08:45 GMT, Michael Winter
<M.Winter@blueyonder.co.invalid> wrote:
[color=blue]
>On Sat, 14 Feb 2004 17:54:25 GMT, Richard Bell <rbell01824@earthlink.net>
>wrote:
>[color=green]
>> I would like to open a 'child' window win and check it's ready state.
>> Unfortunately, when I try to do so, I discover that win.document does
>> not appear accessable from the parent window, see below. Is this by
>> design or am I doing something wrong.[/color]
>
>It depends. If the page in the new window is from a different domain, you
>might get an access error due to security restrictions. Also, you do
>realise that readyState is a non-standard property and might not work on
>all browsers?
>
>At the moment, the problem is that you haven't capitalised the identifier
>properly; JavaScript is case-sensitive, remember. You need to access it
>with:
>
> winObj.document.readyState (not readystate)
>
>You have this problem with addEventListener in a couple of places: you
>write it 'addeventListener'.
>
>Two final comments relate to your HTML.
>
>1) The heading, H1, and script elements are outside of valid blocks. Move
>H1 within BODY and SCRIPT within HEAD or BODY, as appropriate.
>2) The script element is missing the required type attribute. It should be
>written as shown below. Notice that the language attribute (which is
>deprecated) is not necessary when "type" is used.
>
> <script type="text/javascript">
>
>Hope that helps,
>Mike[/color]

Randy Webb
Guest
 
Posts: n/a
#5: Jul 20 '05

re: win.document.readystate - how to access


Richard Bell wrote:
[color=blue]
> Thanks Mike.
>
> As it happens, the documents are definitively from another domain. As
> near as I can tell this means that for an arbitrary URL, there is no
> way within Javascript to determine in the new page has completed
> loading as there is very restricted access to the child window's
> properties and methods. Soooooooooo it seems that Javascript is not
> prepared to handle my needs. Pitty, it's really rather neat.[/color]

One possible solution, that could get kind of nasty, is to use an
HTTPRequestObject to retrieve the .html file, parse it and possibly add
a <base href> tag to make relative links/URLs work properly, and then
write it to a new open window, then you could have access to its
properties/methods.

Only place I know its supported is Moz and IE though.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Closed Thread


Similar JavaScript / Ajax / DHTML bytes