Safari browser new bug in document.write()?

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

    Safari browser new bug in document.write()?

    Hi,

    I am suddenly getting Safari script errors with the following user
    agent:

    Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML,
    like Gecko) Safari/125.8


    In a frameset scenario, the framesetting document (top) contains a
    function:

    function writeDoc(win,tx t){
    var doc=w.window.do cument;
    doc.open("text/html","replace" );
    doc.write(s);
    doc.close();
    }// function

    If a frame contains script such as:

    <script>
    top.writeDoc(to p.someOtherFram eName,"<body>He llo</body>");
    </script>

    then Safari requests a URL in the same path of top but that ends with
    "/text/html", which of course results in a server error 404, "document
    not found".

    Files ending with "/text/html" definitely don't exist in that case. It
    looks very much like the browser is misinterpreting the
    document.open() function.

    Obviously the resulting HTTP request is totally bogus - there is not
    even code that requests data from the network anywhere near the
    function call - the document is written, not loaded.

    It should write the frame so that the text "Hello" appears

    Has anybody else seen this? I don't have a Mac.

    Thanks,

    Bernard
  • Mick White

    #2
    Re: Safari browser new bug in document.write( )?

    Bernard wrote:
    [color=blue]
    > Hi,
    >
    > I am suddenly getting Safari script errors with the following user
    > agent:
    >
    > Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML,
    > like Gecko) Safari/125.8
    >[/color]
    Could be considered a bug, but Safari is very picky about
    "document.write ()":

    <head>
    <script type="text/JavaScript">
    document.write( "Hello")
    </script>
    </head>

    Creates an error(or doesn't work)

    but
    <body>
    <script type="text/JavaScript">
    document.write( "Hello")
    </script>
    </body>
    works as expected.
    Mick.

    Comment

    • Richard Cornford

      #3
      Re: Safari browser new bug in document.write( )?

      Mick White wrote:
      <snip>[color=blue]
      > Could be considered a bug, but Safari is very picky about
      > "document.write ()":[/color]

      Are you sure it is not HTML that it is being picky about?
      [color=blue]
      > <head>
      > <script type="text/JavaScript">
      > document.write( "Hello")
      > </script>
      > </head>
      >
      > Creates an error(or doesn't work)[/color]

      The HEAD element has very restricted content, not including text as a
      child of HEAD. In principle encountering the text output from -
      document.write - in that context should terminate the HEAD and imply the
      opening of the BODY (in HTML, but not XHTML), but maybe Safari cannot
      cope with doing that when using - document.write.
      [color=blue]
      > but
      > <body>
      > <script type="text/JavaScript">
      > document.write( "Hello")
      > </script>
      > </body>
      > works as expected.[/color]

      Whiting text into the BODY is much more normal behaivure.

      Richard.


      Comment

      • Richard Cornford

        #4
        Re: Safari browser new bug in document.write( )?

        Bernard wrote:
        <snip>[color=blue]
        > function writeDoc(win,tx t){[/color]

        The parameters - win - and - txt - are never employed in this function.
        [color=blue]
        > var doc=w.window.do cument;[/color]

        If - w - is not a defined global variable (probably referring to a
        window object) then this line will error.
        [color=blue]
        > doc.open("text/html","replace" );
        > doc.write(s);[/color]

        The variable - s - is not defined in this function.
        [color=blue]
        > doc.close();
        > }// function
        >
        > If a frame contains script such as:
        >
        > <script>
        > top.writeDoc(to p.someOtherFram eName,"<body>He llo</body>");[/color]

        Assuming that named (or IDed) frames will be available as named
        properties of window objects is not reliable.
        top.frames.some OtherFrameName - will work on more browsers, (relative
        references through the - parent - property instead of absolute
        references through - top - would make the system more reliable in
        various presentation context. i.e. with your frameset displayed in
        another (though that is not always desirable)).
        [color=blue]
        > </script>
        >
        > then Safari requests a URL in the same path of top but that
        > ends with "/text/html", which of course results in a server
        > error 404, "document not found".[/color]
        [color=blue]
        > Files ending with "/text/html" definitely don't exist in that
        > case. It looks very much like the browser is misinterpreting the
        > document.open() function.[/color]

        It looks like it may be calling a window.open function instead of a
        document.open function, as the first parameter appears to be being taken
        as a URL. It is difficult to say because the code you have provided will
        error before it does what you describe and so is probably not the code
        that exhibits the problem you are describing (either it is incomplete or
        has been mangled in transcription).

        <snip>[color=blue]
        > It should write the frame so that the text "Hello" appears[/color]
        <snip>

        That is not what the code above should be expected to do.

        Richard.


        Comment

        • Bernard

          #5
          Re: Safari browser new bug in document.write( )?

          Hi Mick,

          Thanks for your reply.

          First my function had errors, it should be:

          function writeDoc(win,tx t){
          var doc=win.window. document;
          doc.open("text/html","replace" );
          doc.write(txt);
          doc.close();
          }// function


          Its purpose is to write the content of an entire frame. Therefore the
          need for the calls doc.open("text/html","replace" ); and doc.close();.

          Thanks for your bug description. I didn't know of such a bug in
          Safari.

          In this context, however, it should not be sensitive to the bug that
          you describe.

          It looks rather like Safari is mixing up two different objects:
          document and window.

          It could be that if I call from a frame

          top.writeDoc(to p.someOtherFram eName,"<body>He llo</body>");

          then Safari fails in such a way that win.window.docu ment returns a
          window instead of a document as expected.

          Could you or some other nice person shed any light on this with the
          following browser?

          "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2
          (KHTML, like Gecko) Safari/125.8"

          Unfortunately I don't have a Mac and the only errors I am getting are
          the 404 entries in the log files. Other Safari versions seem to be ok.

          I am thinking of a testcase such as this:

          <HTML>
          <HEAD>
          <TITLE>Safari document test</TITLE>
          <SCRIPT>
          function writeIt(){
          writeDoc(frame1 ,"<body>Hell o</body>");
          }

          function writeDoc(win,tx t){
          var doc=win.window. document;
          doc.open("text/html","replace" );
          doc.write(txt);
          doc.close();
          }

          </SCRIPT>
          </HEAD>
          <FRAMESET rows="50%,50%" onLoad=writeIt( )>
          <FRAME src="javascript :'<BODY bgcolor=black>' " name=frame1>
          <FRAME src="javascript :'<BODY bgcolor=black>' " name=frame2>
          </FRAMESET>
          </HTML>

          Regards,

          Bernard

          Mick White <mwhite13@BOGUS rochester.rr.co m> wrote:
          [color=blue]
          >Bernard wrote:
          >[color=green]
          >> Hi,
          >>
          >> I am suddenly getting Safari script errors with the following user
          >> agent:
          >>
          >> Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML,
          >> like Gecko) Safari/125.8
          >>[/color]
          >Could be considered a bug, but Safari is very picky about
          >"document.writ e()":
          >
          ><head>
          ><script type="text/JavaScript">
          > document.write( "Hello")
          ></script>
          ></head>
          >
          >Creates an error(or doesn't work)
          >
          >but
          ><body>
          ><script type="text/JavaScript">
          > document.write( "Hello")
          ></script>
          ></body>
          >works as expected.
          >Mick.[/color]

          Comment

          Working...