473,761 Members | 8,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why doesn't this work in Netscape?

This code is supposed to work in Netscape 4+ and IE 4+. It works fine in IE
but in Netscape 7.2, I get a blank page. Any suggestions?

Thanks,
Brett
<html>
<head>

<script language="JavaS cript"><!--
rowArray = new Array();
rowArray[1] = '<form>Row 1: <input type="button" value="Reveal"
onClick="clicke d(2)"><\/form>';
rowArray[2] = 'This is some text for row 1';
rowArray[3] = '<form>Row 3: <input type="button" value="Reveal"
onClick="clicke d(4)"><\/form>';
rowArray[4] = 'Row 4 when clicked reveals this text';
rowArray[5] = '<form>Row 5: <input type="button" value="Reveal"
onClick="clicke d(6)"><\/form>';
rowArray[6] = 'Contents of the last row';

viewArray = new Array();
viewArray[1] = viewArray[3] = viewArray[5] = true;
viewArray[2] = viewArray[4] = viewArray[6] = false;

function refreshTable() {

var output = '<table border="1" width="500">';
for (var i = 1; i <= rowArray.length ; i++) {
if (viewArray[i])
output += '<tr><td>' + rowArray[i] + '<\/td><\/tr>';
}
output += '<\/table>';

if (document.all)
document.all('m yTable').innerH TML = output;
else if (document.layer s) {
document.layers['myTable'].document.open( );
document.layers['myTable'].document.write ln(output);
document.layers['myTable'].document.close ();
}
}

function clicked(x) {
viewArray[x] = !viewArray[x];
refreshTable();
}
//--></script>

</head>

<body onLoad="javascr ipt:refreshTabl e();">
<span id="myTable" style="position :absolute"></span>
</body>
</html>
Jul 23 '05 #1
10 1567
Lee
Brett said:

This code is supposed to work in Netscape 4+ and IE 4+. It works fine in IE
but in Netscape 7.2, I get a blank page. Any suggestions?


I suggest that you ignore any code examples that are supposed
to work in Netscape 4 and IE 4.

That code is completely obsolete.

Jul 23 '05 #2

"Lee" <RE************ **@cox.net> wrote in message
news:ck******** *@drn.newsguy.c om...
Brett said:

This code is supposed to work in Netscape 4+ and IE 4+. It works fine in
IE
but in Netscape 7.2, I get a blank page. Any suggestions?


I suggest that you ignore any code examples that are supposed
to work in Netscape 4 and IE 4.

That code is completely obsolete.

Ok but why exactly doesn't it work in Netscape 7.2?

Thanks,
Brett
Jul 23 '05 #3
Brett wrote:
[snip]
Ok but why exactly doesn't it work in Netscape 7.2?


I'd guess because your logic is that all browsers support either
document.layers or document.all. That would be wrong - e.g. Safari.

Feature detection is great, but only if you use it correctly. Safari
(and I suspect Netscape 7.2) don't support either of the above, they
expect you to use document.getEle mentById or similar.

Also, explicitly putting content into arrays is time consuming and makes
life difficult, consider the code below (with feature detection for
getElementById) . Watch for line wrapping, I can't manually wrap them
because of your code design.

Lastly, this is the craziest way I've seen to hide and show rows.
What's wrong with simply giving each row an id, then hide/show them by
modifying the display attribute? A re-write is below your fixed code -
I think you will find it vastly simpler.

You can also ditch the "<!-- //-->" junk to hide scripts unless you
think someone with Netscape 1.0 or Mosaic will use your page.

Fred.

Partial fix of original code:

<html>
<head>

<script language="JavaS cript">
var rowArray = [
'empty',
'<form>Row 1: <input type="button" value="Reveal"
onClick="clicke d(2)"><\/form>',
'This is some text for row 1',
'<form>Row 3: <input type="button" value="Reveal"
onClick="clicke d(4)"><\/form>',
'Row 4 when clicked reveals this text',
'<form>Row 5: <input type="button" value="Reveal"
onClick="clicke d(6)"><\/form>',
'Contents of the last row',
]

viewArray = new Array();
viewArray[1] = viewArray[3] = viewArray[5] = true;
viewArray[2] = viewArray[4] = viewArray[6] = false;

function refreshTable() {

var output = '<table border="1" width="500">';
for (var i = 1; i <= rowArray.length ; i++) {
if (viewArray[i])
output += '<tr><td>' + rowArray[i] + '<\/td><\/tr>';
}
output += '<\/table>';

if (document.all) {
document.all('m yTable').innerH TML = output;
alert('Using doc.all');
} else {
if (document.layer s) {
alert('Using doc.layers');
document.layers['myTable'].document.open( );
document.layers['myTable'].document.write ln(output);
document.layers['myTable'].document.close ();
} else {
if (document.getEl ementById) {
document. getElementById( 'myTable').inne rHTML = output;
alert('Using doc.GEBI\n' + output);
}

}
}
}

function clicked(x) {
viewArray[x] = !viewArray[x];
refreshTable();
}
</script>

</head>

<body onLoad="javascr ipt:refreshTabl e();">
<span id="myTable" style="position :absolute"></span>
</body>
</html>
Version using element attributes:

<html>
<head><title>Sh ow/Hide Rows</title>

<script type="text/javascript">
function showHide(r) {
if (r.style.displa y == '') {
r.style.display = 'none';
} else {
r.style.display = '';
}
}
</script>
</head>
<body>
<table>
<tr id="row1">
<td>Here is cell 1
<form action="">
<input type="button" value="show/hide row 2"
onclick="showHi de(document.get ElementById('ro w2'))"
</td>
</tr><tr id="row2">
<td>Here is cell 2</td>
</tr>
</table>
</body>
</html>
Jul 23 '05 #4
Fred Oz wrote:
[snip]

Version using element attributes:

Aggghhh! I copied a pasted in two chunks, and of course stuffed it up.
The code should work but only becaue of browser tolerance, here is the
corrected code:

<html>
<head><title>Sh ow/Hide Rows</title>

<script type="text/javascript">
function showHide(r) {
if (r.style.displa y == '') {
r.style.display = 'none';
} else {
r.style.display = '';
}
}
</script>
</head>
<body>
<table>
<tr id="row1">
<td>Here is cell 1
<form action="">
<input type="button" value="show/hide row 2"
onclick="showHi de(document.get ElementById('ro w2'))"

</form>
</td>
</tr><tr id="row2">
<td>Here is cell 2</td>
</tr>
</table>
</body>
</html>
Jul 23 '05 #5
Brett wrote:
This code is supposed to work in Netscape 4+ and IE 4+.
No it isn't.
function refreshTable() {

[snip]

if (document.all)
document.all('m yTable').innerH TML = output;
else if (document.layer s) {
document.layers['myTable'].document.open( );
document.layers['myTable'].document.write ln(output);
document.layers['myTable'].document.close ();
}
}


And that is why it isn't.

"document.a ll" is for MSIE and "document.layer s" is for Netscape 4.
Everything else is a dead duck.
Jul 23 '05 #6
Mark Preston wrote:
Brett wrote:
This code is supposed to work in Netscape 4+ and IE 4+.

No it isn't.


If advertised as "IE4+ and Netscape 4+", then yes, its "supposed" to
work, even if it doesn't work.
function refreshTable() {

[snip]

if (document.all)
document.all('m yTable').innerH TML = output;
else if (document.layer s) {
document.layers['myTable'].document.open( );
document.layers['myTable'].document.write ln(output);
document.layers['myTable'].document.close ();
}
}


And that is why it isn't.

"document.a ll" is for MSIE and "document.layer s" is for Netscape 4.


No, and No.

Opera in Spoof mode honors one or the other. Firefox honors
document.all, and there is even a browser (I don't recall the name, just
recall Jim Ley mentioning it and Richard Cornford may be able to name
it) that supports *both* of those.
Everything else is a dead duck.


See above.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
Randy Webb wrote:
Mark Preston wrote:

<snip>
"document.a ll" is for MSIE and "document.layer s" is
for Netscape 4.


No, and No.

Opera in Spoof mode honors one or the other. Firefox
honors document.all, and there is even a browser (I
don't recall the name, just recall Jim Ley mentioning
it and Richard Cornford may be able to name it)
that supports *both* of those.

<snip>

It was Omniweb

Richard.
Jul 23 '05 #8
Randy Webb wrote:
Mark Preston wrote:

If advertised as "IE4+ and Netscape 4+", then yes, its "supposed" to
work, even if it doesn't work.
Don't know about you, but I didn't see any claim from the provider, just
from the OP. And as far as I can see it is "supposed" to work in MSIE 4+
and Netscape 4 (not "plus").

Which was what I pointed out, rather more briefly.
"document.a ll" is for MSIE and "document.layer s" is for Netscape 4.


No, and No.


Sorry, but "yes and yes".
Opera in Spoof mode honors one or the other. Firefox honors
document.all, and there is even a browser (I don't recall the name, just
recall Jim Ley mentioning it and Richard Cornford may be able to name
it) that supports *both* of those.


I know they do - but that is not what they were set up for. The
"document.a ll" object was for IE and similarly "document.layer s" was for
Netscape 4. It is true, as you said, that other browsers do indeed *use*
those forms, but that is not what they were set up for.

It is always - almost - best to stick to standards and to avoid this
sort of provider-specific code. Granted, in the code referred to it
would have been a lot more difficult to do since both were *extensions*
to the standard that then existed so that additional features could be
used in the specific browsers (and it is because they were extensions
that offered additional features that they were "spoofed" in other
browsers). But that does not, I'm afarid, alter the point that they are
strictly propietary (and in the case of "document.layer s" even version
specific) *extensions* to the standard and cannot be relied on.
Jul 23 '05 #9
Mark Preston wrote:
Randy Webb wrote:
Mark Preston wrote:
<--snip-->
"document.a ll" is for MSIE and "document.layer s" is for Netscape 4.

No, and No.


Sorry, but "yes and yes".


The part of my quote that you snipped said this:

"All others are dead ducks"

And that is patently false, hence my "No, and No.", just as much as
saying "document.a ll is for MSIE" is patently false. To me that says its
for MSIE only, when its not. And for years the assumption by people that
didn't know any different was something along these lines:

if (document.all){
//its IE
}

And that is definitely wrong. While document.all was first implemented
by MSIE and document.layers in NS4, it does not make them for those
browsers alone. Maybe its just the way we interpret what we read *shrug*.
Opera in Spoof mode honors one or the other. Firefox honors
document.all, and there is even a browser (I don't recall the name,
just recall Jim Ley mentioning it and Richard Cornford may be able to
name it) that supports *both* of those.


I know they do - but that is not what they were set up for. The
"document.a ll" object was for IE and similarly "document.layer s" was for
Netscape 4. It is true, as you said, that other browsers do indeed *use*
those forms, but that is not what they were set up for.


That is true, and I agree. But to say, now, that document.all is IE only
and document.layers is NS4 only is just plain wrong. Irrelevant of what
they were originally intended for.
It is always - almost - best to stick to standards and to avoid this
sort of provider-specific code.
That depends on the standard and how well it's implemented. But then, I
am not a big fan of "standards" as I am a fan of whats reality.
Standards (with regards to ECMA) is how things *should* be, not how
things *are*. .toFixed() being probably the simplest and easiest to
screw up yet MS did it. So, do you stick to the "standard", or, do you
make it work around the limitation in the flaw of MS' implementation of it?

Granted, in the code referred to it would have been a lot more difficult
to do since both were *extensions* to the standard that then existed so
that additional features could be used in the specific browsers (and it
is because they were extensions that offered additional features that
they were "spoofed" in other browsers).


That code is *very* simple to make work in "modern" browsers using
document.getEle mentById, and quite trivially at that. Either way, it
doesn't change the simple reality that document.all is not IE4+ and
document.layers is not NS4 (exclusively).

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #10

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

Similar topics

7
4892
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes because then it didn't work in IE. How can I enable this javascipt form validation to work in Netscape? When I use netscape, none of the alert boxes appear. It submits the form without validating anything.
3
1400
by: Jeff Wisnia | last post by:
I'd enjoy learning why this piece of javascript code which I cribbed a couple of years ago (It creates a trail of bubbles following the mouse pointer.) works fine in IE 6.0 and Netscape 4.79, but doesn't do its thing when under Netscape 7.1? I've viewed javascript "test pages" on Netscape 7.1, and they seem to work ok, so I'm presuming there's something obsolete about the code in this page of mine: ...
13
2081
by: AMC | last post by:
Hi, I have the below code in an asp page. When I run this page in IE or Opera it correctly displays the header info and does not redirect me to 'test.html'. However, when I run this in Netscape it goes straight to the redirect page 'test.html' which indicates that javascript is not enabled and it also does not display the header info. Can someone tell me why this is happening? <%@ Language=VBScript%> <%'get header info
3
25320
by: Matt | last post by:
I want to know if readOnly attribute doesn't work for drop down list? If I try disabled attribute, it works fine for drop down list. When I try text box, it works fine for both disabled and readOnly attribute. For example, #1 will work, but #2 doesn't work 1) <SELECT name="streetDirection" class="FormInput" DISABLED> In JavaScript, I have InputForm.streetDirection.disabled = false; 2) <SELECT name="streetDirection" class="FormInput"...
1
1029
by: Mr. x | last post by:
Hello, I am using the dotnet validators one of them is requiredFieldValidator. Is there any reason, that requiredFieldValidator won't work for Netscape ? (I have netscape 7.0, and it seems that requiredFieldValidator doesn't work for netscape, because I have test this for IE. even this is run on the server side).
0
9554
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
9376
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
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9988
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
8813
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...
1
7358
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2788
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.