HTML OK Netscape 4 but a bug in Explorer 4!

Dear experts,

I have a page at http://www.moneysaver.com.au/music/ that raises $ for UNICEF.

It has a logo that stays at the page when people scroll and it works fine in Netscape 4 but causes a script error in Explorer 4. It is DHTML.

Can someone please help fix the script so it work either on both browsers or at least continues working inNetscapr 4 but doesn't cause a script error in Explorer 4?

If you can't help, please share this question with colleagues and help me raise money for starving kids.
mindwaveAsked:
Who is Participating?
 
fritsCommented:
Well here's your answer:
Because IE does'nt seem to understand Style Sheets just
skip over the script if IE.
Just add the first and last line (just the bracket!) to your script!

<script language="javascript">

if (navigator.appName != "Microsoft Internet Explorer") {

var IW= 0;
var IH= 0;
var PX= 0;
var PY= 0;
var ZIN= 0;
var us= null;
var IMGW= 150;
var IMGH= 18;
var LSAFETY= 20;
var TSAFETY= 17;

function branding()  {  
   oldIW= IW;  oldIH= IH;  oldPX= PX;  oldPY= PY;  
   if ((window.innerHeight != oldIH)||(window.innerWidth != oldIW)||(window.pageXOffset != oldPX)||(window.pageYOffset != oldPY))    {    
      if (us == null)      {      
         for (i=0; i<document.layers.length; i++)        {        
            us= document.layers[i];        
            if (us.id == "MoneySaver")          break;        
         }
      }
      if(window != window.top){  
         var ourDoc= "";  
         var ourDocTest= 0;  
         for(i=0;i<window.top.frames.length; i++){      
            if((window.top.frames[i].innerWidth * window.top.frames[i].innerHeight)>ourDocTest){      
               ourDoc= window.top.frames[i];      
               ourDocTest= window.top.frames[i].innerWidth * window.top.frames[i].innerHeight;      
            }
         }
      }
      if((ourDoc == self)||(!ourDoc)){      
         if (us != null)        {        
            us.visibility= "hide";        
            IH= window.innerHeight;        
            IW= window.innerWidth;        
            PX= window.pageXOffset;        
            PY= window.pageYOffset;        
            (IH > IMGH) ? us.top= (IH+PY-(IMGH+TSAFETY)) : us.top= 0;
            (IW > IMGW) ? us.left= (IW+PX-(IMGW+LSAFETY)) : us.left= 0;        
            for (i=0; i<document.layers.length; i++)          {          
               templay= document.layers[i];          
               if (templay.zIndex > ZIN)  ZIN= (templay.zIndex + 1);          
            }        
         us.zIndex= ZIN;      
         us.onmouseover= neat_mouseover;      
         us.onmouseout= neat_mouseout;        
         us.visibility= "show";        
         }      
      }    
   }  
}

function neat_mouseover(){  
   if(us != null){    
      window.status="Save Money and Get Stuff Free!";    return true;  
   }
}

function neat_mouseout(){  
   if(us != null){    
      window.status="";    return true;  
   }
}

if(window.document.location.pathname != "/ad_container/pop.html")   setInterval("branding()",100);

}
</script>

0
 
jbirkCommented:
I went to try and work the solution for you, but when I viewed the source, I noticed that it is all in one line (the end of lines have been removed).  It is almost impossible to read code like this, and it would take like 20-40 minutes to make it readable before even starting to work on it.  Do you have a version with the end of lines?  I can help you if you can provide such a document.
-Josh
0
 
jbirkCommented:
frits: What do you mean: "Because IE does'nt seem to understand Style Sheets..."?
Of course IE 4 understands style sheets.  It actually has more ability and is more robust than netscape on style sheets.  The problem is that netscape and IE refer to layers in different ways.  So the code needs to basically be written once for IE and once for netscape with a check to see which browser is viewing it to decide which code to execute.
-Josh
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
fritsCommented:
jbirk: You're right!
The question was:
"Can someone please help fix the script so it work either on both browsers or at least
  continues working in Netscape 4 but doesn't cause a script error in Explorer 4? "
If you want to rewrite the script for IE 4. Please do!
-frits
0
 
jbirkCommented:
frits: I would consider it, but currently I can't read the source since it's all in one line, and I figure that he has to have a version with the end of lines, but removed them for space (which is normally good).
mindwave: If you don't have a copy of the file with the end of lines, tell me and I'll try to mkae the code readable on my own, but don't want to waste the time to do so if you already have such a file.
-Josh
0
 
fritsCommented:
jbirk: eyetroubles?
the script-code is on THIS PAGE!


0
 
jbirkCommented:
Well, since you copied the netscape branding functions from geocities (who doesn't seem to have any disclaimer about this, so it's perfectly reasonable), I suppose the easiest thing to do would be just copy their ie branding functions as well.
They use a javascript include file for these functions which is the best way so that the users don't have to wait for the unneeded code to download, only the necesary code is downloaded.
So, I'll post their ie code, and then show a method to decide which code to use.  If you can't use include files, then all the code can just be pasted onto the page.

I can't say I fully understand everything in this code, but if you have questions about it, I'll try to figure it out.

Here's the IE code:

var IW= 0;
var IH= 0;
var PX= 0;
var PY= 0;
var brand= null;
var IMGW= 150;
var IMGH= 18;
var LSAFETY= 40;
var TSAFETY= 17;
var gandalf= 0;

var ourLays= new Array();
var alldivs= new Array();
alldivs= document.all.tags("DIV");


function BrandInit(){
if (brand!= null) return;
else{
  ID_CHECK:  for (i=0; i<alldivs.length; i++){
    if ((gandalf==0)&&(alldivs(i).id == "MoneySaver")){
      gandalf=1;
      brand= alldivs(i);
      continue ID_CHECK;
    }
    if(gandalf==1){
      if(alldivs(i).id== "nh1"){
        pop_menu= alldivs(i);
        continue ID_CHECK;
      }
    ourLays[ourLays.length]= alldivs(i);
    }
  }
}
brand.onmouseover= neat_mouseover;
brand.onmouseout= neat_mouseout;
}

function neat_mouseover(){
window.status= "Free Home Pages";
return true;
}

function neat_mouseout(){
window.status= "";
return true;
}

function BrandPosition(){
if(brand!= null){
  IH= document.body.clientHeight;
  IW= document.body.clientWidth;
  PX= document.body.scrollLeft;
  PY= document.body.scrollTop;
  brand.style.top= (IH+PY-(IMGH+TSAFETY));
  brand.style.left=(IW+PX-(IMGW+LSAFETY));
  for (i=0; i<alldivs.length; i++){
    if (alldivs(i).style.zIndex > brand.style.zindex)
      brand.style.zindex= (alldivs(i).style.zIndex + 1);
  }
}
}

function BrandShow(toggle){
if(brand!= null)
  brand.style.display= toggle;
}

function Branding(){
if (navigator.appVersion.indexOf("Mac") == -1){
  oldIW= IW;
  oldIH= IH;
  oldPX= PX;
  oldPY= PY;
  if ((document.body.clientHeight != oldIH)||(document.body.clientWidth != oldIW)||(document.body.scrollLeft != oldPX)||(document.body.scrollTop != oldPY)){
    BrandInit();
    if(window != window.top){
      var ourDoc= "";
      var ourDocWidth= 0;
      var ourDocHeight= 0;
      var ourDocTest= 0;
      var ourDocTemp= 0;
      var ourDocFull= "";
      var allFrames= window.top.document.all.tags('frame');
      if(allFrames.length==0) allFrames= window.top.document.all.tags('FRAME');
      for(i=0;i<allFrames.length; i++){
        var tempLoc= allFrames(i).src;
        if(tempLoc.indexOf("http") == -1){
          ourDocTemp= allFrames(i).width * allFrames(i).height;
          if(ourDocTemp>ourDocTest){
            ourDoc= allFrames(i);
            ourDocTest= ourDocTemp;
          }
        }
      }
      frameIndex= window.top.location.href.substring(0,window.top.location.href.lastIndexOf("/"));
      ourDocFull= frameIndex+"/"+ourDoc.src;
    }
    if((brand != null)&&((ourDocFull== window.location.href)||(!ourDoc)||(!ourDocFull))){
      BrandShow("none");
      BrandPosition();
      BrandShow("");
    }
    else{
      if(brand != null){
        BrandShow("none");
      }
    }
  }
}
}

setInterval("Branding()",100);


OK, after pasting that into a file named ie.js, paste your current javascript code for netscape into a filed named nn.js, then put this code into your document (make sure to remove your current div tag for the branding, and make sure the image directories are correct in the following code):
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
if (document.all) //true only in IE
 {document.write('<DIV CLASS="MoneySaver" ID="MoneySaver" STYLE="position:absolute;top:1;display:none;" ALIGN="right">');
  document.write('<IMG SRC="http://www.moneysaver.com.au/images/logo_page.gif" width="154" height="28" ALT="Save Money and Get Stuff Free" BORDER="0"></DIV>');
 document.write('<SCRIPT LANGUAGE="javascript1.2" SRC="ie.js"></SCRIPT>');
}
else //netscape
{
 document.write('<DIV CLASS="MoneySaver" ID="MoneySaver" STYLE="position:absolute;top:1;visibility:hide;" ALIGN="right">');
 document.write('<IMG SRC="http://www.moneysaver.com.au/images/logo_page.gif" width="154" height="28" ALT="Save Money and Get Stuff Free" BORDER="0"></DIV>');
 document.write('<SCRIPT LANGUAGE="javascript1.2" SRC="nn.js"></SCRIPT>');
}
// -->
</SCRIPT>

I think that should do the trick.  Be careful when copying that code because any line with document.write may wrap which need to be in one line.  You will get an unterminated string literal if it wraps.

If you have troubles, put the changed code on-line under like a temp name, and I'll look at it, and try to figure it out.

Hope this works for you,
Josh
0
 
mindwaveAuthor Commented:
Wow, thanks for the input! I think we're nearly there!

I've tidied up the code at http://www.moneysaver.com.au/music/
so if you view the code it will now be easier to read!

Hey guys I looked at the Geocities code too, but thought it referred to some code that I couldn't read.

Fritz you'll note that I included your fix so there is now no longer an Explorer script error.

Josh, your advice looks like the solution I need, but I'm not sure exactly how to implement it...

Will this mean I need two different versions of the page? That is one for explorer 4 and one for navigator 4? Or can I have just the one page that will now work both browsers?

Josh, are you able to provide the complete code in one page that that will work both browsers?

I have increased the points to 300 which almost uses up my points, but this is important...

Thanks for both your help so far!

Kind regards


Jonathan
0
 
jbirkCommented:
Yes, this will work fine in one page, it just takes two javascript source pages.  (does your server allow those?)

If you post your e-mail address, I can send you the three files tested and debugged.  It's easier to just send files via e-mail attachements, cause there's no copy paste errors, and there's n confusion in where to put what, etc.
Of course, If I did all this work, I would want the points as well, so you have to reject frits's answer so I can provide the answer.

-Josh
0
 
fritsCommented:
To Jonathan: do what you like! (I don't care....)

To Josh:You're probably in desperate need of points!
I must say:
"The more I see of men, the better I like my dog."

-fritz
0
 
jbirkCommented:
>>To Josh:You're probably in desperate need of points!
fritz: well, sort of.  I'm trying to work my way into the top 15 experts in JavaScript and HTML, and possibly eventually into the top 100 overall.  Also, the t-shirt promotion is kind of cool!
-Josh
0
 
mindwaveAuthor Commented:
Hey guys,

Why can't I give you both points?

My email address is joncm@yahoo.com

Regards


Jonathan
0
 
jbirkCommented:
You can!  Sort of.  Ask a question in customer service worth 0 points, and say that we were both helpful in solving the problem and you would like to give points to both of us, and they will credit points to your account to post another question with equal points or they will post the question themselves (I've seen both done before).  Make sure to refer them to this question by number.

I'll send those three files to you as soon as I get a chance (probably tomorrow).

-Josh
0
 
jbirkCommented:
Jonathan,
Did you receive the file I sent you?
I attached it this time...

-Josh
0
 
jbirkCommented:
OK, you have accepted frits's answer, and given him all the points.
Where you still intending to give me some points as well?
*please*
-Josh
0
 
mindwaveAuthor Commented:
Whoops!

I meant to give them to you both!

Josh, I'll email customer service at EE and see if they can give you the rest of the points I have.

By the way, is it ok to credit your name and email address as the creator of the code on the page? Let me know and I'll make sure you get the credit for the source code. You deserve it!

Kind regards and bless you...

Jonathan
0
 
jbirkCommented:
Well, you can;t actually *e-mail* EE customer service.  You have to post a question in that area for 0 points requesting to split the question and give me 300 points as well.  They will either credit 300 to your account, or post a question worth 300 for me.  I've seen them do this before.  Just refer them to this question (by number).
Thanks,
-Josh
0
 
fritsCommented:
Surprise!
I just got back from my vacantion, and gues what?
I have earned 1200 points with this question!
Thanx a lot
- Fritz
0
 
fritsCommented:
Pleasant surprise...!
I just got back from my vacation, and guess what?
I have earned 1200 points with this question!
Thanx a lot
- Fritz

0
 
mindwaveAuthor Commented:
Hey Fritz!

I've no idea how that happened... Please share some points with Josh if at all possible. If you do, I will also credit you on the page at www.moneysaver.com.au/music as helping with the source code.

Josh, I did email customer service about this. When I have more points I'll do as you suggest and ask customer service to fix it up properly this time!

Regards

Jonathan



0
 
jbirkCommented:
customer service doesn't have an e-mail address anymore.  They exclusively use the topic area experts exchange within the customer service category.  If you want any service you have to ask them for help there.  The question you ask can be 0 points, so you don't have to wait.  They should credit you with more points in order to ask a new question to give me the points.
-Josh
0
 
fritsCommented:
To: jbirk & mindwave
If I can help just let me know!
- Fritz
Maybe I should ask a difficult question for jbirk?


0
 
jbirkCommented:
If you have anything you're working on that you need help with Fritz, I'd be happy to help!
-Josh
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.