473,396 Members | 1,987 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,396 software developers and data experts.

documnet.write

Hi,
I don't know all the ins and outs of javascript so I don't know
if there is something simple i am missing. Why will this code
not display the browser width while the later will?

this does not work
<script language="JavaScript1.2"><!--

if (document.all)
document.write(document.body.clientWidth)

//-->
</script>

This does work
<script language="JavaScript1.2"><!--

document.write("width=")
if (document.all)
document.write(document.body.clientWidth)

//-->
</script>
Obviously the browser has to pass my if statement, but I don't see
what the problem is if the bottom works in my browsers. win IE6 and Firefox1

Chuck
Jul 23 '05 #1
8 2775
VK
> this does not work
<script language="JavaScript1.2"><!--

if (document.all)
document.write(document.body.clientWidth)

//-->
</script>


This works OK on IE 6

Firefox doesn't support document.all collection, so your "if" branch is
never executed.

Try this instead (with some more respect to the language syntacs):
....
if (document.all) {
document.write(document.body.clientWidth);
}
else if (document.getElementById) {
document.write(document.width);
}
else {
document.write('Hey, get yourself a normal browser!');
}

Where are some tiny difference in clientWidth and width from browser to
browser, so you may need to manually adjust results (width+/-delta)
Jul 23 '05 #2
On Mon, 25 Oct 2004 13:55:04 +0200, VK <sc**********@yahoo.com> wrote:
this does not work
<script language="JavaScript1.2">
The language attribute has been deprecated in favour of the (required)
type attribute for over five years. Moreover, specifying the language
variant as 1.2 is positively dangerous and should always be avoided unless
you explicitly want to invoke 1.2 parsing rules (and you don't - trust me).
<!--
Similarly, hiding script contents is an out-dated practice that shouldn't
be continued any more. All browsers currently in use understand what a
SCRIPT element is, even if they have no intention of executing the
contents. If you really need to prevent a user agent from reading the
script, move it into an external file.
if (document.all)
document.write(document.body.clientWidth)

[snip]
if (document.all) {
document.write(document.body.clientWidth);
}
else if (document.getElementById) {
document.write(document.width);
}
else {
document.write('Hey, get yourself a normal browser!');
What a helpful message.
}


I don't see what the tests presented by you or the OP have to with what
you're trying to accomplish. What bearing does support of document.all or
document.getElementById have on the ability to find browser dimensions?

A cross-browser solution has been presented by Richard Cornford in another
thread
(<URL:http://groups.google.com/groups?threadm=35742ecc.0409091231.6b4fb829%40post ing.google.com>).
Note the correction later in that thread.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
VK
> The language attribute has been deprecated in favour of the (required)
type attribute for over five years.
Actually I did not touch this part of the OP's posting. If we started on it
then:

1.
A language indication in any form was needed only for a short period of time
between IE 3.0 - IE 3.02
At that time IE tried to interpret any script (unless "JavaScript" is
specified) as its newly introduced VBScript code. Sometimes it produced
*funny* results. In IE 3.02 they (besides adding input-file) fixed IE's
brains, and it never was an issue anymore.
Any other browsers never used anything but JavaScript, so for them it was
not an issue from the very beginning.
As of 2004 A.D. <script></script> is enough, any extra would be a useless
"white noise".

2.
<!-- // --> is still suggested: to hide inline scripts from webbots. They
got much smarter over the last ten years, so you don't see too often index
like:
"My Home Page"
var i = 1; var b = "";...
myhomepage.com >

Still it is better to be safe than sorry.

3. A cross-browser solution has been presented
by Richard Cornford in another thread


This is a reputable name, and I'm sure in the quality of his code. But I
think that the OP wanted to have HER code to work, not Mr. Cornford's one.
And it's good - look how much extra info she got (if she took time to read
our postings of course :-) - and how much would she miss by copy-paste 3rd
party code, however perfect it is.
Jul 23 '05 #4
"VK" <sc**********@yahoo.com> writes:
As of 2004 A.D. <script></script> is enough, any extra would be a useless
"white noise".
However, adding a "type" attribute would make it valid HTML, which some
people still care about :)
2.
<!-- // --> is still suggested: to hide inline scripts from webbots.
Any webbot that doesn't recognize the script tag, but does recognize
comments, is ... well, badly broken.
Still it is better to be safe than sorry.


.... but that is a point.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #5
VK wrote:
this does not work
<script language="JavaScript1.2"><!--

if (document.all)
document.write(document.body.clientWidth)

//-->
</script>

This works OK on IE 6

Firefox doesn't support document.all collection, so your "if" branch is
never executed.


Actually, it does. It just won't let you test for it using
if(document.all). But, alert(document.all) in Firefox PR gives this:
object HTML document.all class

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #6
On Mon, 25 Oct 2004 16:01:03 +0200, VK <sc**********@yahoo.com> wrote:
The language attribute has been deprecated in favour of the (required)
type attribute for over five years.

[snip]
1.
A language indication in any form was needed only for a short period of
time between IE 3.0 - IE 3.02
They are dead. An interesting aside, though.

Even if those versions were a concern, it doesn't negate the fact that
trying to invoke v1.2 is a bad idea.

[snip]
As of 2004 A.D. <script></script> is enough, any extra would be a
useless "white noise".
As Lasse said, that would result in invalid HTML. Unless you have a
*really* good reason to do otherwise, all documents should be valid.
2.
<!-- // --> is still suggested: to hide inline scripts from webbots.
As I said in my earlier post: "If you really need to prevent a user agent
from reading the script, move it into an external file."

If a bot isn't smart enough to ignore the script, I highly doubt it would
read the src attribute, download the resource, and analyse it.

[snip]
3.
A cross-browser solution has been presented by Richard Cornford in
another thread


This is a reputable name, and I'm sure in the quality of his code. But I
think that the OP wanted to have HER code to work, not Mr. Cornford's
one.


There's nothing wrong with the OP's code, other than the erroneous test.
It's perfectly valid, syntactially, so it will work. Whether it works as
desired is another matter, but the OP didn't provide enough information to
determine that. Unless an error occurs, the write method will write
something.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7
VK
Any webbot that doesn't recognize the script tag, but does recognize
comments, is ... well, badly broken.
Still it is better to be safe than sorry.


... but that is a point.


Exactly! Just to start with, check this:
http://www.altavista.com/web/results...1&kls=0&stq=80
and look what kind of "oops" happened with Indiana University of
Pennsylvania

OK, this is why eventually AltaVista lost all its former glory and why the
most people is googling instead of altavisting.
Still AltaVista is not an amateur search site, and still used for
cross-search.
Jul 23 '05 #8
VK wrote:
Any webbot that doesn't recognize the script tag, but does recognize
comments, is ... well, badly broken.

Still it is better to be safe than sorry.


... but that is a point.

Exactly! Just to start with, check this:
http://www.altavista.com/web/results...1&kls=0&stq=80
and look what kind of "oops" happened with Indiana University of
Pennsylvania


http://validator.w3.org/check?uri=ht...lib.iup.edu%2F
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #9

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

Similar topics

10
by: Greg Hurlman | last post by:
I've got what I'm sure is a very simple problem. In an ASP page, I am trying to write out 4 fields from a recordset in succession: Response.Write rs("LastName") Response.Write rs("Suffix")...
1
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
0
by: hari krishna | last post by:
hi all, My requirement is to generate xl reports throu Asp.Net without installing xl on web server computer. i am using Response object and wrtifile method as below. i dont know whether it is...
8
by: Ben | last post by:
Hi all, Just wondering how to write (using document.write) to a table cell. I have table with 3 rows and 3 colums. I want to write from within the Javascript to say third column of a first row....
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
0
by: staleb | last post by:
Hi I want to open a MSWord document on the clients PC/MSWord, the solution I use now is this: <script language=vbscript runat=Server> <!-- sub OpenDoc(strLocation) set objWord =...
3
by: Kevin | last post by:
Is it possible to develop an Active Document Full Server or a Container application using C#? Thanks, Kevin.
0
by: jiatiejun | last post by:
VB 6.0 ActiveX Documnet upgrade to VS.Net ? I want upgrade a C/S WinForm Client to B/S Browse safe is not importment VB 6.0 ActiveX Document is good way
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...

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.