Safari browser new bug in document.write()?

B

Bernard

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,txt){
var doc=w.window.document;
doc.open("text/html","replace");
doc.write(s);
doc.close();
}// function

If a frame contains script such as:

<script>
top.writeDoc(top.someOtherFrameName,"<body>Hello</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
 
M

Mick White

Bernard said:
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
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.
 
R

Richard Cornford

Mick White wrote:
Could be considered a bug, but Safari is very picky about
"document.write()":

Are you sure it is not HTML that it is being picky about?
<head>
<script type="text/JavaScript">
document.write("Hello")
</script>
</head>

Creates an error(or doesn't work)

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.
but
<body>
<script type="text/JavaScript">
document.write("Hello")
</script>
</body>
works as expected.

Whiting text into the BODY is much more normal behaivure.

Richard.
 
R

Richard Cornford

Bernard wrote:
function writeDoc(win,txt){

The parameters - win - and - txt - are never employed in this function.
var doc=w.window.document;

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

The variable - s - is not defined in this function.
doc.close();
}// function

If a frame contains script such as:

<script>
top.writeDoc(top.someOtherFrameName,"<body>Hello</body>");

Assuming that named (or IDed) frames will be available as named
properties of window objects is not reliable.
top.frames.someOtherFrameName - 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)).
</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.

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).

It should write the frame so that the text "Hello" appears
<snip>

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

Richard.
 
B

Bernard

Hi Mick,

Thanks for your reply.

First my function had errors, it should be:

function writeDoc(win,txt){
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(top.someOtherFrameName,"<body>Hello</body>");

then Safari fails in such a way that win.window.document 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>Hello</body>");
}

function writeDoc(win,txt){
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top