473,836 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript problem in Firefox

Hi - I am trying to use Javascript to put material inside a table
(i.e. alongside the previous material) if the user's screensize is
big enough and outide the table (beneath table) if it isn't.

The following code (tag properties and other extraneous material
removed) works in IE but not Firefox:
<table>
<tr><td>
first set of material
</td>
<script language="text/javascript">
<!--
if ((screen.width> =1024) && (screen.height> =768))
{
document.write( "<td>");
}
else
{
document.write( "</tr></table>");
}
</script>
second set of material
<script language="text/javascript">
<!--
if ((screen.width> =1024) && (screen.height> =768))
{
document.write( "</td></tr></table>");
}
</script>

If you "view source" in Firefox, you can see that it is treating
this as a single piece of script, with only the first opening script
tag and second closing script tag highlighted in purple.

Can anybody help?

Thanks!

Karin

P.S.
This is the effect it's meant to produce for high resolution
screens:
<table>
<tr><td>
first set of material goes here
</td>
<td>
second set of material goes here inside table
</td></tr></table>

And for low ones:
<table>
<tr><td>
first set of material goes here
</td>
</tr></table>
second set of material goes here outside table

Aug 31 '05 #1
14 12663


Karin Jensen wrote:

<script language="text/javascript"> Use
<script type="text/javascript">
or
<script language="JavaS cript" type="text/javascript">
<!-- ^^^^
Simply remove that, or if you think there is any need to comment out
script code then do it properly and insert the comment closer
//--> </script>

before the closing </script>.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 31 '05 #2

"Karin Jensen" <k_******@mailb locks.com> wrote in message
news:Pine.GSO.4 .44.05083115502 80.21034-100000@austen.. .
Hi - I am trying to use Javascript to put material inside a table
(i.e. alongside the previous material) if the user's screensize is
big enough and outide the table (beneath table) if it isn't.


There are actually a coupla basic problems with your script which may, or
may not be causing the problems - but fixing them first should be a priority
just to get them off the suspects list. ;^)

There may be others but what I see off the top of my head is:

1) You've got the "language" attribute mixed up with the "type" attribute.
Change " language="text/javascript" " to " type="text/javascript" ". You
can happily not include the "language" attribute at all.

2) Your "hiding" comments are broken - you're beginning the comments
("<!--") but never ending them ("// -->"). This is probably causing the
color-coding issues you're seeing in FireFox (that's a guess). Personally I
would remove the comments completely - it's an archaic technique that
doesn't really offer anything today (although I'll admit it's a hard habit
to break).

Fix those and see where you are.

Lastly, and I apologize in advance for waxing philosophic here (feel free to
ignore me), some thoughts:

I think that you're concept is flawed. You don't want the screen size- you
want to the browser size. It's wrong to assume that the user will always
run their browser maximized... and even if the browser were maximized the
screen real-estate useful for a web page is whittled away by tool bars,
explorer bars, search bars, favorites bars and candy bars.

There's a strong correlation between screen size and browsing behavior:
users with low screen resolutions nearly always maximize their browsers,
users with very high screen resolutions rarely do. However users with high
screen resolutions are also much more likely to leave real-estate gobbling
interface elements visible as well.

In any case one way to get the "browser size" (the actual size of the
browsers display area) is to examine the size of the current "BODY" tag
(this code, of course, that there IS a body tag available to be examined):

document.getEle mentsByTagName( 'BODY')[0].clientHeight
document.getEle mentsByTagName( 'BODY')[0].clientWidth

I've only tested this on IE 6.x and FireFox 1.x... it may or may not work on
others.

Of course just because their browser STARTS at that size is no reason to
assume that they'll leave it that size for the duration of their session.
Your implementation should be able to deal with this behavior - at the very
least the content of the site shouldn't present assumptions about the
current state of the browser if you've only checked that state at the
beginning of the session.

Again, sorry for the lecture. I'm a human factors consultant by trade so
this kind of thing hits home. ;^)

In any case I hope this helps,

Jim Davis
Aug 31 '05 #3
"Jim Davis" <ne********@vbo ston.com> writes:
document.getEle mentsByTagName( 'BODY')[0].clientHeight
Why this convoluted way of getting at document.body? I don't think
there is a browser implementing document.getEle mentsByTagName and not
document.body (document.body was implemented by IE 3) both are part of
the W3C DOM level 1 HTML standard).

The clientHeight property is not standardized (it was introduced by IE
4), nor is its position on the body element. If one wants to find the
size of the browser's document viewport, the FAQ has more general ways
of doing it: <URL:http://jibbering.com/faq/#FAQ4_9>
Of course just because their browser STARTS at that size is no reason to
assume that they'll leave it that size for the duration of their session.


Ah, yes. The devil is in the details, too.
At least, after a page has loaded, the user can see what he is doing by
resizing it.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 31 '05 #4
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:ll******** **@hotpop.com.. .
"Jim Davis" <ne********@vbo ston.com> writes:
document.getEle mentsByTagName( 'BODY')[0].clientHeight
Why this convoluted way of getting at document.body? I don't think
there is a browser implementing document.getEle mentsByTagName and not
document.body (document.body was implemented by IE 3) both are part of
the W3C DOM level 1 HTML standard).


Is there there any better answer than "that's what worked off the top of my
head"? ;^)

Isn't the great thing about JavaScript that there's ALWAYS another way (and
usually a better way) to do something?
The clientHeight property is not standardized (it was introduced by IE
4), nor is its position on the body element. If one wants to find the
size of the browser's document viewport, the FAQ has more general ways
of doing it: <URL:http://jibbering.com/faq/#FAQ4_9>


Then, by all means, use the better code. As I noted, I only tested on IE 6x
and FireFox 1x (clientHeight is supported in both).

The primary point was NOT to use the screen size for such a decision.
Of course just because their browser STARTS at that size is no reason to
assume that they'll leave it that size for the duration of their session.


Ah, yes. The devil is in the details, too.
At least, after a page has loaded, the user can see what he is doing by
resizing it.


Exactly... really until you constantly check for changes you're making broad
assumptions about an environment with one check. From a usability POV this
is just isn't good.

Jim Davis
Aug 31 '05 #5
Jim Davis wrote:
2) Your "hiding" comments are broken - you're beginning the
comments ("<!--") but never ending them ("// -->").
Ick! That fixed it. I feel very silly now. Thanks to you and
Martin for pointing this out. I just couldn't see for looking that
I'd made that mistake once and copied it into both bits of code.
Sometimes IE doesn't help by running broken code, so that you think
the error is a mistake in another browser. (Most of the page is in
PHP, but the size stuff has to be client side. I don't use
Javascript much and it shows!)
I think that you're concept is flawed. You don't want the screen
size- you want to the browser size. It's wrong to assume that the
user will always run their browser maximized... and even if the
browser were maximized the screen real-estate useful for a web
page is whittled away by tool bars, explorer bars, search bars,
favorites bars and candy bars.


I agree - this was just a first stab. I'll use the method suggested
in <URL:http://jibbering.com/faq/#FAQ4_9> The next step after that
is to deal with window resizes during the same session. I have to
move in fairly small steps or I'd never get anything working...

Thanks again,

Karin
Sep 1 '05 #6
On Wed, 31 Aug 2005 13:29:40 -0400, "Jim Davis"
<ne********@vbo ston.com> wrote:
In any case one way to get the "browser size" (the actual size of the
browsers display area) is to examine the size of the current "BODY" tag
(this code, of course, that there IS a body tag available to be examined):

document.getEl ementsByTagName ('BODY')[0].clientHeight
document.getEl ementsByTagName ('BODY')[0].clientWidth


Why on earth would you use this, rather than

document.body ???

They're equally as standard, and document.body is much, much more
supported.

Jim.
Sep 1 '05 #7
"Jim Ley" <ji*@jibbering. com> wrote in message
news:43******** ******@news.ind ividual.net...
On Wed, 31 Aug 2005 13:29:40 -0400, "Jim Davis"
<ne********@vbo ston.com> wrote:
In any case one way to get the "browser size" (the actual size of the
browsers display area) is to examine the size of the current "BODY" tag
(this code, of course, that there IS a body tag available to be examined):

document.getE lementsByTagNam e('BODY')[0].clientHeight
document.getE lementsByTagNam e('BODY')[0].clientWidth


Why on earth would you use this, rather than

document.body ???


For the same reason I'd already given - because that's what I remembered off
the top of my head.

No special reason other than that. ;^)

Sometimes what sticks to your noodle (and works) isn't always the most
concise option.

Jim Davis
Sep 1 '05 #8
"Karin Jensen" <k_******@mailb locks.com> wrote in message
news:Pine.GSO.4 .44.05090109051 90.11722-100000@austen.. .
Jim Davis wrote:
2) Your "hiding" comments are broken - you're beginning the
comments ("<!--") but never ending them ("// -->").


Ick! That fixed it. I feel very silly now. Thanks to you and


Well - definatetly don't feel silly. Broken code outnumbers working code in
this world by a very healthy margin: you're not alone and you never will be.
I think that you're concept is flawed. You don't want the screen


I agree - this was just a first stab. I'll use the method suggested
in <URL:http://jibbering.com/faq/#FAQ4_9> The next step after that
is to deal with window resizes during the same session. I have to
move in fairly small steps or I'd never get anything working...


No problem... the majority of programming is chipping away at a problem.

You know - a journey of a thousand miles begins, well in this case with
fixing some comments. ;^)

Good luck!

Jim Davis
Sep 1 '05 #9
JRS: In article <Pine.GSO.4.44. 0508311550280.2 1034-100000@austen>,
dated Wed, 31 Aug 2005 16:01:21, seen in news:comp.lang. javascript,
Karin Jensen <k_******@mailb locks.com> posted :
Hi - I am trying to use Javascript to put material inside a table
(i.e. alongside the previous material) if the user's screensize is
big enough and outide the table (beneath table) if it isn't.


You have been told to use window size rather than screen size. That's a
naive response; if, as an author, you elect to present the material
wider, then the reader can increase the window size rather readily in
order to get your preferred effect.

In general, it seems better for a reader to be able to widen the window
rather than to be forced, because of the size that the window initially
happened to be, to have the material use more height than necessary.
You may be able to arrange that the material adjusts it position to suit
the window size currently in use, as happens for ordinary text.

For instance, when I arrive at a new site, I generally have a 640 px
wide window, because that is what suits my local home page and my
LinkFile; I *expect* to widen the window when I am ready to read it.

However, you cannot judge with any reliability whether your material
(unless largely graphic) will fit in a given screen width.

My default window size normally shows about 70-80 characters of my
default fixed-width font, but Ctrl-Mousewheel will alter this by a
factor of about 1.5 each way. Others may use more variation;
particularly the visually-handicapped.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 1 '05 #10

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

Similar topics

12
1955
by: Howard Kaikow | last post by:
Yesterday, I decided to try Firefox. I've encountered a behavior that is either a bug in Firefox or a bug in my Javascript code. I'll try to explain the problem, hoping that this newsgroup can (in)validate my Javascript code. First, I'll describe the purpose of the Javascript code. I often have a need to post a URL to something at my own web site, e.g., http://www.standards.com/Sorting/SortPerformanceComparison-Description.html. It is...
5
2221
by: LRW | last post by:
(Sorry if this is a repost...my newsreader keeps crashing on the posting--I don't know if the message going out or not) For some reason this javascript just won't work in Firefox. It works fine in IE, though. I know, IE is a bit more permissive than IE, and sometimes lets errors work when they shouldn't. But from what I can see, I just don't see what's wrong.
13
8323
by: John Smith | last post by:
I am using IE 6.0 from http://www.javaworld.com/javaworld/jw-07-1996/jw-07-javascript-p2.html I gather that "If you need to test a number of command lines, you can reduce the keystrokes by typing javascript: (remember the colon) in the Location box. Navigator displays a "JavaScript typein" frame at the bottom of the window. Type the command line you want to try, and press Enter. "
8
3682
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
4
2337
by: lmarceglia | last post by:
Hi, I have this website that doesn't work in Firefox 1.5: www.pianetaluca.com The HTML source is: <TITLE>PianetaLuca</TITLE> </HEAD>
7
9627
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script language="JavaScript"> var cntlName; var eleTarget = document.getElementById('hiding'); function showOrHide(){
11
3443
by: minnesotti | last post by:
Hi there, I subscribed to a photographic pictures-hosting website which is heavy on JavaScript. My preferred latest browser Mozilla Firefox does not work with it -- no pictures are displayed and no buttons react to clicking. The website's helpdesk says it should work with Firefox, and could not offer any more advices. The JavaScript Console shows that there are numerous errors occuring. It looks like the web browser does not recognise...
8
1933
by: Matt Kruse | last post by:
http://news.zdnet.com/2100-1009_22-6121608.html Hackers claim zero-day flaw in Firefox 09 / 30 / 06 | By Joris Evers SAN DIEGO--The open-source Firefox Web browser is critically flawed in the way it handles JavaScript, two hackers said Saturday afternoon. An attacker could commandeer a computer running the browser simply by crafting a Web page that contains some malicious JavaScript code, Mischa Spiegelmock and Andrew Wbeelsoi...
16
2340
by: Eric | last post by:
I have a user of a web application written in Java/JSP that is unable to login to the site simply because certain links on the page do not run when they are clicked. Other popups using Javascript on the same page work correctly. It appears to be isolated to 1-2 machines in a particular network. I cannot verify whether these machines have had virus/spyware scans, but I do know the user is running Firefox 2.1 and IE 7 with the same...
12
2621
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more than one line and the text simply overlaps the sub-menus below it. I thought i had got around this by placing empty 'spacers' like so; oFoldMenu.make('sub3','')//spacer unfortunately, i have just viewed the site in IExplorer and it has added...
0
9826
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9674
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10560
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10604
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10261
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6984
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5831
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4466
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.