[Javascript] Code that used to work in Netscape no longer does

Peter Brunone peter at brunone.com
Thu Apr 11 15:02:18 CDT 2002


	Sure you can; I've done it many times, including right now just to be sure
(it's one of the few things you CAN change in NN4).

	Audra, the problem is that you're trying to get the color of the body
before the body exists.  When I put this script right before the </body>
tag, it populates all fields correctly.  There may be other issues, but this
fixes your original problem.

Cheers,

Peter

|-----Original Message-----
|From: javascript-admin at LaTech.edu On
|Behalf Of Golden Troll
|
|You can't change elements (bgcolor) on the fly w/ NN4.
|
|Peace and Respects,
|Scott Gahres
|Owner
|Golden Troll Ventures hemp at goldentroll.com  http://goldentroll.com
|
|-----Original Message-----
|From: javascript-admin at LaTech.edu On
|Behalf Of WolfSong
|
|Hi,
|
|I wrote this script with a group during a CIS course and it has always
|worked fine until I loaded it into Netscape Navigator 4.7. It sends back
|a
|NaN value and freezes Netscape. The code still works fine in up to IE
|5.50
|(haven't tested higher). Can anyone tell me what's wrong?
|
|Thanks,
|Audra Seigars
|
|CODE:
|<Head>
| <SCRIPT LANGUAGE="JavaScript">
| <!--
|     red = parseInt(document.bgColor.substring(1, 3), 16);
|     green = parseInt(document.bgColor.substring(3, 5), 16);
|     blue = parseInt(document.bgColor.substring(5, 7), 16);
|
|     function hexChar(n) {
|  if (n == 10)
|     return "A";
|  else if (n == 11)
|     return "B";
|  else if (n == 12)
|     return "C";
|  else if (n == 13)
|     return "D";
|  else if (n == 14)
|     return "E";
|  else if (n == 15)
|     return "F";
|  else
|     return "" + n;
|     }
|     function toHex(n, d) {
|  var s = "";
|  for (var i = 0; i < d; i++) {
|     s = hexChar(n % 16) + s;
|     n = Math.floor(n / 16);
|     }
|     return s;
|     }
|     function report() {
|  document.colors.redHex.value = toHex(red, 2);
|  document.colors.greenHex.value = toHex(green, 2);
|  document.colors.blueHex.value = toHex(blue, 2);
|     }
|     function changeColors() {
|  red += 3;
|  green += 5;
|  blue += 7;
|
|  document.bgColor =
|     toHex(red, 2) +
|     toHex(green, 2) +
|     toHex(blue, 2);
|  report();
|     }
| //-->
|     </SCRIPT>
|</HEAD>
|<BODY ONLOAD = "report()">
|<FORM NAME="colors">
|     <CENTER>
|     <INPUT TYPE="button" VALUE="Test Color" ONCLICK="changeColors()">
|     <FONT COLOR="red">Red</FONT>:
|     <INPUT TYPE="text" NAME="redHex" SIZE=3>
|     <FONT COLOR="green">Green</FONT>:
|     <INPUT TYPE="text" NAME="greenHex" SIZE=3>
|     <FONT COLOR="blue">Blue</FONT>:
|     <INPUT TYPE="text" NAME="blueHex" SIZE=3>
|     </CENTER>
|</FORM>
|</BODY>




More information about the Javascript mailing list