win.document.readystate - how to access

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Bell

    win.document.readystate - how to access

    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>Javascri pt Test</TITLE>
    </HEAD>
    <SCRIPT language="JavaS cript">
    var win =
    open('http://faqts.com/knowledge-base/community/index.phtml/id/601');
    var iq = 0;
    var q = "";
    q += 'typeof window.document ' + typeof(window.d ocument) + '\n';
    q += 'typeof window.document .readystate ' +
    typeof(window.d ocument.readySt ate) + '\n';
    q += 'typeof window.addevent Listener ' +
    typeof(window.a ddEventListener ) + '\n';
    q += 'typeof win.document ' + typeof(win.docu ment) + '\n';
    q += 'typeof win.document.re adystate ' +
    typeof(win.docu ment.readyState ) + '\n';
    q += 'typeof win.addeventLis tener ' + typeof(win.addE ventListener) +
    '\n';
    </SCRIPT>

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

    </BODY>
    </HTML>
  • Michael Winter

    #2
    Re: win.document.re adystate - how to access

    On Sat, 14 Feb 2004 17:54:25 GMT, Richard Bell <rbell01824@ear thlink.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 addEventListene r in a couple of places: you
    write it 'addeventListen er'.

    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@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Richard Bell

      #3
      Re: win.document.re adystate - 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@bluey onder.co.invali d> wrote:
      [color=blue]
      >On Sat, 14 Feb 2004 17:54:25 GMT, Richard Bell <rbell01824@ear thlink.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 addEventListene r in a couple of places: you
      >write it 'addeventListen er'.
      >
      >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]

      Comment

      • Richard Bell

        #4
        Re: win.document.re adystate - 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@bluey onder.co.invali d> wrote:
        [color=blue]
        >On Sat, 14 Feb 2004 17:54:25 GMT, Richard Bell <rbell01824@ear thlink.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 addEventListene r in a couple of places: you
        >write it 'addeventListen er'.
        >
        >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]

        Comment

        • Randy Webb

          #5
          Re: win.document.re adystate - 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
          HTTPRequestObje ct 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.javas cript FAQ - http://jibbering.com/faq/

          Comment

          Working...