473,416 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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,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
Jul 23 '05 #1
4 5992
Bernard wrote:
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.

Jul 23 '05 #2
Mick White wrote:
<snip>
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.
Jul 23 '05 #3
Bernard wrote:
<snip>
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).

<snip> 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.
Jul 23 '05 #4
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

Mick White <mw******@BOGUSrochester.rr.com> wrote:
Bernard wrote:
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.


Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kim Forbes | last post by:
Hi, I realize my first problem is that I'm using browser detection and not feature detection. Maybe someone can help me understand feature detection. This script works in every browser that I...
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
2
by: drew197 | last post by:
I am a newbie. This is someone else's code which I have to modify to work in Mozilla and Safari. The changes I made so far have allowed it to work in Mozilla but not Safari. It seems to be...
4
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in...
34
by: Simon Wigzell | last post by:
document...focus() will scroll the form to move the specified text field into view on everything I have tried it with except Safari on the MAC. The form doesn't move. Any work around? Thanks.
2
by: darren | last post by:
I have a small Javascript problem with that mutch love web browser safari, I tested the code on all other browsers PC (Win) and Linux and IE on the mac and it seams to work ok, but for some reason...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
5
by: loveshack | last post by:
Can anyone help me please (i am quite a novice, but having fun learning). Im not sure if this is an ASP problem, a javascript problem or a browser problem. Firstly, everything i have written...
15
by: GinnTech | last post by:
I have a site that works perfectly in IE6 IE7 FF2 FF3 but not in the latest Safari. Here is the issue. I am attempting to call functions within a flash object. When trying to attempt to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.