473,406 Members | 2,769 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,406 software developers and data experts.

Javascript in netscape navigator

Please take a look at my code. I made a script to scroll the contents of DIV
tag. It works in IE, but not NN. I tried to use document.getElementById(id)
function. It didn't work at all. I just want it to run in NN7.1 which is
latest. Thank you in advance.

<HTML>
<HEAD>
<TITLE>TEST</TITLE>
<SCRIPT LANGUAGE="Javascript">
<!--
var div1interval;
function div1init()
{
for(j=0; j<2;j++)
{
div1.innerHTML += 1+"<BR>";
}
while((div1.scrollHeight/2) <= parseInt(div1.style.height))
{
div1.innerHTML += div1.innerHTML;
}
}
function div1start()
{
div1interval=setInterval("div1scent();div1.scrollT op+=5;",100);
}
function div1scent()
{
if(div1.scrollTop == (div1.scrollHeight-parseInt(div1.style.height)))
{
div1.scrollTop = (div1.scrollHeight/2)-parseInt(div1.style.height);
}
}
-->
</SCRIPT>
</HEAD>
<BODY>
<div ID="div1" STYLE="overflow-y:hidden; width:100px; Height:101px;
display:block;"
onclick="alert('height: '+this.scrollHeight+', Top: '+this.scrollTop)">
<SCRIPT LANGUAGE="Javascript">
<!--
div1init();
div1start();
-->
</SCRIPT>
</div>
</BODY>
</HTML>
Jul 20 '05 #1
4 2600
wo*****@aol.com (Sangwoo Im) writes:
Please take a look at my code. I made a script to scroll the contents of DIV
tag. It works in IE, but not NN. I tried to use document.getElementById(id)
function. It didn't work at all.
That would depend on how you used it, obviosuly.
I just want it to run in NN7.1 which is latest.
Aim higher :) There are other browsers than IE and Mozilla/Netscape.
First, Does your HTML validate? (Answer: No. Make it before you go any
further).

HTML requires a DOCTYPE delaration.
<HTML>
<HEAD>
<TITLE>TEST</TITLE>
<SCRIPT LANGUAGE="Javascript">
In HTML 4, the type attribute is required. The language attribute is
not necessary when you have type.
<script type="text/javascript">
<!--
No need for HTML-like comments.
var div1interval;
function div1init()
{
for(j=0; j<2;j++)
{
div1.innerHTML += 1+"<BR>";
innerHTML is proprietary. I assume this function is only for testing
though (filling the div with some arbitrary context).

I don't think "scrollHeight" works the same in Mozilla/Netscape as in IE.
It doesn't give the height of the entire content, just the height of the
visible area. You need a different way to calculate the height of the hidden
content.

You are using "div1" as a global variable, but you haven't initialized
it. In IE that would make it point to the element with id="div1". In
other browsers it won't.

This question comes up a lot. Is it time for an entry in the FAQ?

<FAQENTRY>Why doesn't the global variable "divId" refer to the element
with id="divId"?

It does in Internet Explorer, but not in *many* other browsers. The
recommended way of referring to an element with id="foo" is
document.getElementById("foo")
In order to support older browsers that doesn't implement this W3C DOM
method, fallback to proprietary features can be used. In Internet Explorer
4 (and WebTV?), you can use document.all["foo"] . In Netscape 4, maybe
you can use document.layers["foo"] , but only if the element is absolutely
positioned (or created with the Netscape 4 proprietary <layer> tag).

<URL:http://www.mozilla.org/docs/web-developer/upgrade_2.html#dom_access>
</FAQENTRY>
(better ideas obviously welcome)
function div1start()
{
div1interval=setInterval("div1scent();div1.scrollT op+=5;",100);
Same problem here. Change "div1" into "document.getElementById('div1')"
}
function div1scent()
{
Add
var div1 = document.getElementById("div1");
so you won't have to change "div1" everywhere.
if(div1.scrollTop == (div1.scrollHeight-parseInt(div1.style.height)))
You compare with ==. You would probably want to use ">=", since you scroll
in steps of 5, so you can miss the exact value.

You use "div1.style.height" to get the current height. Just be aware that it
only works when div1 has its height set in the style attribute (as it does).
Another, non-standard, method is to use div1.offsetHeight.

.... <div ID="div1" STYLE="overflow-y:hidden; width:100px; Height:101px;
"overflow-y" is a proprietary IE property, not CSS. Try "overflow:hidden".
display:block;"


display:block is default for a div.
I still can't get it working in Opera.
/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 20 '05 #2
Thank you for your replying post.

I will keep reading thru what you wrote multiple times then try to fix it.

However, I wonder whether a documentation which explains the difference of
Javascript among various browsers exists or not.

Anybody has an idea?
Jul 20 '05 #3
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:he**********@hotpop.com...
<snip>
This question comes up a lot. Is it time for an entry in the FAQ?
This is another of those cases where the question itself is not really
asked often but the information is very frequently included as part of
answers. That would suggest that maybe it should be in the FAQ (as other
entries (eval (#FAQ4_40), for example) got in by the same criteria).
<FAQENTRY>Why doesn't the global variable "divId" refer to
the element with id="divId"?
I wonder whether that question shouldn't be worded "Why doesn't the
global variable "divId" always refer to the element with id="divId"?" -
or - "Why doesn't the global variable "divId" refer to the element with
id="divId" in all browsers?" (though the latter would mean re-wording
the opening sentence).
It does in Internet Explorer, but not in *many* other
We could quibble about "*many*" as reproducing this IE feature seems to
be quite common among modern browsers, Mozilla/Gecko browsers being
primarily the ones that render this IE shortcut invalid in cross-browser
scripting.
browsers. The recommended way of referring to an element
with id="foo" is
document.getElementById("foo")
In order to support older browsers that doesn't implement
this W3C DOM method, fallback to proprietary features can be
used. In Internet Explorer 4 (and WebTV?), you can use
document.all["foo"] . In Netscape 4, maybe you can use
document.layers["foo"] , but only if the element is absolutely
positioned (or created with the Netscape 4 proprietary
<layer> tag).

<URL:http://www.mozilla.org/docs/web-deve...html#dom_acces s> </FAQENTRY>
(better ideas obviously welcome)


In Netscape 4 elements with - position:relative - also appear in the -
layers - collection so maybe the last sentence should go "..., but only
if the element is CSS positioned (or created with ...".

Thinking about the role of FAQ entries, it seems to me that the purpose
of posting a URL reference to a part of the FAQ is to avoid repeating
the same explanation in response to questions. To that end I would
probably be a bit more long-winded and want to include an example
fallback function:-

<longer_proposal>
A common shortcut in accessing DOM elements that have ID attributes
(introduced by IE and reproduced in some other browsers) is to use the
ID string as an identifier for the element. However, not all browsers
support this shortcut and more general methods exist for accessing IDed
elements. The widest support is offered by the document.getElementById
method, which is part of the W3C DOM standard and implemented in most
modern browsers (including IE from version 5.0). So an element with
id="foo" can be referenced with:-

var el = document.getElementById("foo");

In order to support older browsers that doesn't implement this W3C DOM
method, fallback to proprietary features can be used. In Internet
Explorer 4 (and WebTV?), you can use document.all["foo"] . In Netscape
4, maybe you can use document.layers["foo"] , but only if the element is
CSS positioned (or created with the Netscape 4 proprietary <layer> tag).
E.G.:-

function getElementWithId(id){
if(document.getElementById){ //prefer the W3C DOM method.
return document.getElementById(id);
}else if(document.all){ //fallback for IE 4(and some others)
return document.all[id];
}else if(document.layers){ //fallback for Net 4 (sometimes)
return document.layers[id]; //Will not work for layers nested
//within layers. A recursive
//search of nested layers would
//be needed to find such a layer
}
} // remember to test the value returned from this function as some
// browsers do not support any of the methods used here.
</longer_proposal>

- but FAQ entries also need to be short so maybe not.

Richard.
Jul 20 '05 #4
On Mon, 8 Dec 2003 15:04:32 -0000, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> wrote:
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
<FAQENTRY>Why doesn't the global variable "divId" refer to
the element with id="divId"?


I'm reading very infrequently at the minute, whilst I do pick up the
FAQENTRY's when later reviewing, the main motivation for a session at
editing the FAQ is lots of FAQENTRY's being seen, if you could CC me
these it may get them done quicker...
- but FAQ entries also need to be short so maybe not.


I like the idea, and think it would be a valuable addition, but
shorter for sure!

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #5

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

Similar topics

2
by: news frontiernet.net | last post by:
I have key entered and tried to run example 4-6 from Dany Goodmans DYNAMIC HTML book, version one that is on pages 94-96. This is part of my effort to learn JavaScript. I checked each byte and...
1
by: Toralf Lund | last post by:
Is there any way at all I can get a user's login name from within JavaScript on Unix/Linux with Mozilla browser. If not, how about the home directory? I know there are *usually* variables...
6
by: chuck clark | last post by:
Hi, I understand that for security and other reasons that javascript does not support writing/reading to text files. I am looking for a way that will however. This is what i am trying to do. I...
3
by: annon | last post by:
I've noticed that some problems come up frequently that are of importance in writing web pages, because they're pretty fundamental points. For general reference, here are some collected...
5
by: Florian Proch | last post by:
Hi all... i'm currently working for a big project to construct a website. We need to support some browser and OS : IE 5.0 -> IE 6, Mozilla 1.2 -> 1.7, Opera 5 -> Opéra 7.5x, Netscape 4.75 -> NS...
4
by: Ryan Gaffuri | last post by:
I know that this works. I just don't get the syntax. I know its checking the OS. just not sure how it works. var v = navigator.appVersion.toUpperCase() if (1+v.indexOf('WIN98') os =...
2
by: Keyser | last post by:
On most my pages, I use Javascript to play a sound. It works fine in Netscape 4.7, Netscape 7.2, Firefox 1.0, IE5 and IE6 using Windows98 as the operating system. However, using WindowsXP as the...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.