473,804 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById(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="Javas cript">
<!--
var div1interval;
function div1init()
{
for(j=0; j<2;j++)
{
div1.innerHTML += 1+"<BR>";
}
while((div1.scr ollHeight/2) <= parseInt(div1.s tyle.height))
{
div1.innerHTML += div1.innerHTML;
}
}
function div1start()
{
div1interval=se tInterval("div1 scent();div1.sc rollTop+=5;",10 0);
}
function div1scent()
{
if(div1.scrollT op == (div1.scrollHei ght-parseInt(div1.s tyle.height)))
{
div1.scrollTop = (div1.scrollHei ght/2)-parseInt(div1.s tyle.height);
}
}
-->
</SCRIPT>
</HEAD>
<BODY>
<div ID="div1" STYLE="overflow-y:hidden; width:100px; Height:101px;
display:block;"
onclick="alert( 'height: '+this.scrollHe ight+', Top: '+this.scrollTo p)">
<SCRIPT LANGUAGE="Javas cript">
<!--
div1init();
div1start();
-->
</SCRIPT>
</div>
</BODY>
</HTML>
Jul 20 '05 #1
4 2621
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.getEle mentById(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="Javas cript">
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 "scrollHeig ht" 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.getEle mentById("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=se tInterval("div1 scent();div1.sc rollTop+=5;",10 0);
Same problem here. Change "div1" into "document.getEl ementById('div1 ')"
}
function div1scent()
{
Add
var div1 = document.getEle mentById("div1" );
so you won't have to change "div1" everywhere.
if(div1.scrollT op == (div1.scrollHei ght-parseInt(div1.s tyle.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.hei ght" 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.offsetHeig ht.

.... <div ID="div1" STYLE="overflow-y:hidden; width:100px; Height:101px;
"overflow-y" is a proprietary IE property, not CSS. Try "overflow:hidde n".
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/rasterTriangleD OM.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>Wh y 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.getEle mentById("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:relati ve - 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_proposa l>
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.getEle mentById
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.getEle mentById("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 getElementWithI d(id){
if(document.get ElementById){ //prefer the W3C DOM method.
return document.getEle mentById(id);
}else if(document.all ){ //fallback for IE 4(and some others)
return document.all[id];
}else if(document.lay ers){ //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*****@litote s.demon.co.uk> wrote:
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
<FAQENTRY>W hy 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.javas cript 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
2979
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 position back against the book for syntax errors but still cannot get this script to work. I tells me that; 1. Line 49 has a missing ";" at bye 13 2. Line 89 has a missing object at byte 1
1
3766
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 accessible via navigator.preferences() that contain the info, but I have found none that can *always* be expected to exist. - Toralf
6
8250
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 want to develop a simple html page that is run locally on a windows 2000 box in IE. The page will have a browse button to select a source folder, either locally or a network computer on same lan. A destination folder, either locally or a...
3
2032
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 solutions. 1. Opens a new Window at maximum size: window.moveTo(0,0,screenX=0,screenY=0) window.resizeTo(screen.availWidth+2,screen.availHeight+6)
5
1776
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 7.2, Safari and for OS : Win95/98/NT/Me/2000/XP, MacOS 9/10, Linux. I have some problems with browser on different OS. For example i have write a javascript who make a automatic submit when the page is reload.
4
1729
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 = 'Win98'; else if (1+v.indexOf('WINNT') os = 'WinnT';
2
2193
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 operating system, the entire Netscape 7.2 browser and Firefox 1.0 browser shuts down when I try to use the Back button on these pages. Is there some setting in Windows XP that is causing this or is there something I can add to the Javascript to...
2
3908
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 http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it is a server problem but was told it is not possible, therefore assuming it is a client script problem? the script works last time...
8
3681
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
9716
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
9595
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
10354
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...
0
10101
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
9177
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6870
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
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
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.