473,770 Members | 6,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

This script works in IE. How to port to Netscape, Firefox, Opera?

6 New Member
I am needing, and would appreciate expert assistance for a Javascript program that I am using in a Website. The script is a Text and Image Fader, which only works on IE, but what I am trying to do is get it to work across the NS, FF and OPR browsers. What I have done is added global variables at the beginning of the existing script, however, I am not sure where to go from there. Even though the script is not showing any errors, and is still working in IE with the added code, I know there still needs to be a reference within the script to call the variables, but I am not sure how to add them.

I am providing the full code below for the script. This is not time sensitive, however, I am hoping that I can receive a response back in 3 days.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  6. <meta name="ProgId" content="FrontPage.Editor.Document">
  7. <title>Wear Gear Text Fader</title>
  8.  
  9. <SCRIPT LANGUAGE="JavaScript">
  10.  
Expand|Select|Wrap|Line Numbers
  1. <!-- Begin
  2. var isDOM = (document.getElementById ? true : false);
  3. var isIE4 = ((document.all && !isDOM) ? true : false);
  4. var isNS4 = (document.layers ? true : false);
  5. function getRef(id) {
  6. if (isDOM) return document.getElementById(id);
  7. if (isIE4) return document.all[id];
  8. if (isNS4) return document.layers[id];
  9. }
  10. function getSty(id) {
  11. return (isNS4 ? getRef(id) : getRef(id).style);
  12. }
  13.  
  14. // add as many or as few messages as you would like
  15. var msg=new Array()
  16. msg[0]="<CENTER>You can see more scripts like this one...</CENTER>";
  17. msg[1]="<CENTER>...when you visit the JavaScript Source.</CENTER>";
  18. msg[2]="<CENTER>Just type in \"<A href='http://javascript.internet.com/'>javascript.internet.com</A>\"</CENTER>";
  19. msg[3]="<CENTER>Your computer can handle the rest.</CENTER>";
  20.  
  21. // set your first set of colors.  Use as many or as few as you wish.
  22. var colors1=new Array("ffffff", "eeeeff", "ddddff", "ccccff", "bbbbff", "aaaaff", "9999ff",
  23. "8888ff", "7777ff", "6666ff", "5555ff", "4444ff", "3333ff","2222ff", "1111ff", "0000ff")
  24.  
  25. //set your second set of colors
  26. // *** must have exactly the same number of colors as the array above ***
  27. var colors2=new Array("ffffff", "ffeeee", "ffdddd", "ffcccc", "ffbbbb", "ffaaaa", "ff9999",
  28. "ff8888", "ff7777", "ff6666", "ff5555", "ff4444", "ff3333", "ff2222", "ff1111", "ff0000")
  29.  
  30. //set the height of the display in pixels
  31. high=60;
  32.  
  33. //set the width of the display in pixels
  34. wide=350;
  35.  
  36. //set the pixel coordinates for the upper left hand corner of the display
  37. Xpos=220;
  38. Ypos=180;
  39.  
  40. // move the display away from the edges of the background
  41. pad=15;
  42.  
  43. // set the background color of the display
  44. bgcol="ffffff";
  45.  
  46. //add a background image if you want.
  47. // *** for no image, just leave empty quotes (ex. cellbg=""; ) ***
  48. cellbg="faderbg.jpg";
  49.  
  50. // set the font
  51. fntFam="verdana,helvetica,arial";
  52. fntSize=14;
  53.  
  54. // set how how many seconds you want the message to stay remain at totality.
  55. pause=2.5;
  56.  
  57.  
  58. // Do not edit these values below!!!
  59.  
  60. icolor=0;
  61. mcolor=1;
  62. imsg=0;
  63. spWidth=wide-(2*pad);
  64. totality=false;
  65. glowing=true;
  66. var theMsg="";
  67. var cellcontent="";
  68. pause=pause*1000;
  69. if(cellbg.length>4){cellbg=" background="+cellbg}
  70. else{cellbg="";}
  71.  
  72. function doPause(){
  73.    totality=false; t=setTimeout("changecolor()",pause);
  74.    }
  75. function initiate(){
  76.    getContentColor();
  77.    getMsg();
  78.    getCellContent();
  79.    if(document.all){
  80.    msgbg.innerHTML=cellcontent;
  81.    msgfade.innerHTML=theMsg;
  82.    msgbg.style.posLeft=Xpos;
  83.    msgbg.style.posTop=Ypos;
  84.    msgfade.style.posLeft=Xpos+pad;
  85.    msgfade.style.posTop=Ypos+pad;
  86.    t=setTimeout("changecolor()",50);}
  87.    if(document.layers ? true : false){
  88.    document.msgbg.document.write(cellcontent);
  89.    document.msgbg.document.close();
  90.    document.msgfade.document.write(theMsg);
  91.    document.msgfade.document.close();
  92.    document.msgbg.left=Xpos;
  93.    document.msgbg.top=Ypos;
  94.    document.msgfade.left=Xpos+pad;
  95.    document.msgfade.top=Ypos+pad;
  96.    t=setTimeout("changecolor()",100);}
  97.    }
  98. function changecolor(){
  99.    if(totality==true){doPause();}
  100.    else{
  101.    getMsg();
  102.    getContentColor();
  103.    if(document.all){
  104.    msgfade.innerHTML=theMsg;
  105.    t=setTimeout("changecolor()",50);}
  106.    if(document.layers){
  107.    document.msgfade.document.write(theMsg);
  108.    document.msgfade.document.close();
  109.    t=setTimeout("changecolor()",70);}
  110.    }
  111.    }
  112. function getFadeColor(){
  113.    icolor=icolor-1;
  114.    if(mcolor==1){contentcolor=colors1[icolor];}
  115.    else{contentcolor=colors2[icolor];}
  116.    }
  117. function getGlowColor(){
  118.    icolor=icolor+1;
  119.    if(mcolor==1){contentcolor=colors1[icolor];}
  120.    else{contentcolor=colors2[icolor];}
  121.    }
  122. function changemsg(){
  123.    if(imsg==msg.length-1){imsg=0; mcolor=1;}
  124.    else if(imsg != msg.lenght-1 && mcolor==1){imsg=imsg+1; mcolor=0;}
  125.    else{imsg=imsg+1; mcolor=1;}
  126.    }
  127. function getContentColor(){
  128.    if(icolor==colors1.length-1 && glowing==true){
  129.    getFadeColor(); glowing=false; totality=true;}
  130.    else if(icolor < colors1.length && glowing==true){
  131.    getGlowColor();}
  132.    else if(icolor < 1 && glowing==false){changemsg(); getGlowColor(); glowing=true;}
  133.    else{getFadeColor();}
  134.    }
  135. function getMsg() {
  136.    theMsg="<span style='font-size:"+fntSize+"pt; font-family:"+fntFam+"; width:"+spWidth+";'>"
  137.    theMsg+="<B><font color="+contentcolor+">"+msg[imsg]+"</font></B> "
  138.    theMsg+="</span>"
  139.    }
  140. function getCellContent(){
  141.    cellcontent="<TABLE height="+high+
  142.    " width="+wide+" bgcolor="+bgcol+" cellpadding=0 cellspacing=0><TR><TD"+cellbg+"> </TD></TR></TABLE>"}
  143.  
  144. //  End -->
Expand|Select|Wrap|Line Numbers
  1. </script>
  2.  
  3. </head>
  4.  
  5.  
  6. <BODY onLoad="initiate()">
  7.  
  8. <DIV id=msgbg style="position: absolute;"></DIV>
  9. <DIV id=msgfade style="position: absolute;"></DIV>
  10.  
  11. </body>
  12.  
  13. </html>
Thank you in advance for your efforts, and I look forward to your expertise in this matter and will credit your contribution within the script.

Sincere regards,
Michael M.
Sep 28 '07 #1
10 1637
pbmods
5,821 Recognized Expert Expert
Heya, Muir. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

[CODE=javascrip t]
JavaScript code goes here.
[/CODE]
Sep 28 '07 #2
gits
5,390 Recognized Expert Moderator Expert
hi ...

moved from the js-articles section to the forum ... please don't post questions in the articles sections ...

kind regards
Sep 28 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
You're using document.all and document.layers . That sort of testing is 10 years old when IE4 and NS4 were battling it out.

Use document.getEle mentById. It is supported in all modern browsers. Get rid of references to 'all' and 'layers' and have one set of code for all browsers.
Sep 28 '07 #4
Muir
6 New Member
hi ...

moved from the js-articles section to the forum ... please don't post questions in the articles sections ...

kind regards

Thank you, gits, for the heads-up.

Muir
Sep 28 '07 #5
Muir
6 New Member
Heya, Muir. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

Expand|Select|Wrap|Line Numbers
  1. JavaScript code goes here.
  2.  
Thank you, pbmods, this is my first time posting (I am a Newbie), and from now on I will try to follow the guidelines.

Muir
Sep 28 '07 #6
Muir
6 New Member
You're using document.all and document.layers . That sort of testing is 10 years old when IE4 and NS4 were battling it out.

Use document.getEle mentById. It is supported in all modern browsers. Get rid of references to 'all' and 'layers' and have one set of code for all browsers.
Acoder, what about the older browsers? A lot of clients the Website is geared towards may be using older versions. However, I will definitely use the doc.getElement reference, but, how do I accomodate older versions?

Sincere regards,

Muir
Sep 28 '07 #7
drhowarddrfine
7,435 Recognized Expert Expert
Older browsers? Both of those guys? As mentioned, you will probably have a hard time finding anyone using browsers that old. And if you try and support them by using code that old, you are ignoring the majority of your viewers.
Sep 29 '07 #8
acoder
16,027 Recognized Expert Moderator MVP
Acoder, what about the older browsers? A lot of clients the Website is geared towards may be using older versions. However, I will definitely use the doc.getElement reference, but, how do I accomodate older versions?
Older browsers such as IE4 and NS4 are almost extinct. You can degrade gracefully for them if you want, but if you try and provide support for them, you're holding yourself back. All the effort for what gain?

In your code, to make it work in newer browsers, use the part which checks for document.all as your code. Discard the document.layers part because that won't work. In the code that's left, replace "pos*" with the *, e.g. posLeft becomes left.

Make those changes and see if that works.
Sep 29 '07 #9
Muir
6 New Member
Older browsers? Both of those guys? As mentioned, you will probably have a hard time finding anyone using browsers that old. And if you try and support them by using code that old, you are ignoring the majority of your viewers.

Thank you, drhowarddrfine, and I have come to the conclusion that most definitely you are right. I am trying to accommodate everyone, but the coding can become very ambiguous (creating errors), and unnecessary if I want to reach the majority.

Thanks, again.

Sincerely,
Muir
Oct 1 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2341
by: uberderf | last post by:
I have the following web page setup: http://angels.uberderf.com/glossary.html I have a 2 column table layout which is a glossary of terms and their meanings. When you view this page in firefox the first row displays with a lot of space below the two cells. The rest of the table looks as it was intended to look. This same page viewed in Mozilla looks correct or how it was intended to look. Even IE displays the page as intended.
5
1665
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible. Can anyone point out which one it is and how to make it both netscape and MS browser compatible? I hope if I can make the script compatible for those two at extreme, it will probably work with most browser out there. As you would notice, this form...
3
1528
by: Bob | last post by:
I've got a fair amount of Javascript coding that works great in IE and Opera, but is completely ignore in Firefox and Netscape. See: www.bridgemate.net/BeachWatchers/Regis.htm Right after the <FORM NAME="Regis".....tag I have <div onClick='getRadios(document.Regis)'> which sends control to getRadios() when the user clicks anywhere on the
7
1578
by: Dayo | last post by:
Hello folks. Sorry if this seems a bit silly, I have no experience with this type of code. Here is a fading script for an Image Gallery I am looking to fix. It works with IE and Safari but not with Firefox and Netscape. Actually, when I say it doesn't work, I mean you have to refresh the page before the fade happens and once that is done once, it works on that image. for that session. Here is the code: // Fade In Script
0
9591
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
9425
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
10225
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
10053
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
8880
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
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
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
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
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.