Forum Moderators: open

Message Too Old, No Replies

Javascript not working in IE but Firefox is

javascript and internet explorer

         

slimnutty5000

7:34 pm on Oct 2, 2007 (gmt 0)

10+ Year Member



Well, i am sort of a beginner/intermediate to javascript but I have spent over 8 hours and spoken to a couple coders and still cant fix my problem.

PROBLEM:
I use about 7 different Javascript functions on my website and ALL work fine in Firefox, but there are 3 that will not work in Internet Explorer since yesterday!

I have been using all 7 functions for the last month or so and have had no problems in either browser up until yesterday.

The only thing i did was play with organization of my scripts, i had a lot of code on the < head > part of my pages so i wanted to put all that into a linked JS file. So i did and it worked fine in Firefox, but notIE. so i put the code back into the < head > and only 3 functions work in IE but ALL work in Firefox.

The 7 functions i use are: (all work fine in Firefox)
- Slashdot Menu (DHTML collapsable menu)
- Image carousel (image loop with links and stop function)
- Show/Hide (using tables not DIV)
- TR Rollover highlight (highlight rows with color on rollover)
- Jump Menu
- Swap image rollover
- Open Browser window

Only these work in Internet Explorer:
- Jump menu, Swap image, and Open browser window

The code i used for the JS link is :
<script type="text/javascript" src="slashfiles/menu.js"></script>
<script type="text/javascript" src="scripts/scripts.js"></script>
...................................................................
My Header looks like this:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta>
<title></title>
<meta>..............
<link (style sheets)>
<script type="text/javascript">
(My swap image, jump menu, open browser window functions)
</script>
<script>
(My TR rollover highlight functions)
</script>
<script type="text/javascript" src="slashfiles/menu.js"></script>
<script type="text/javascript" src="scripts/scripts.js"></script>
<body OnLoad="init(); fillup();">
......................................................................

So i hope that is enough info to work with.
I really appreciate any kind of help i can get.

JAB Creations

7:49 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure but I would attempt to test for DOM objects like this...

if (object) {alert('this object is supported in this browser'}

- John

slimnutty5000

8:01 pm on Oct 2, 2007 (gmt 0)

10+ Year Member



How do i do a test like that?
Are there any tools out there that test JS code for errors?

JAB Creations

8:04 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at the scripts that Internet Explorer is not executing. if (condition) Your conditions are going to in most cases make use of DOM objects. So read my original post and try it out. :)

- John

slimnutty5000

8:29 pm on Oct 2, 2007 (gmt 0)

10+ Year Member



This is the entire script for the TR Rollover highlight:

...............................................................
var highlightbehavior="TR"

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor){
source=ie? event.srcElement : e.target
if (source.tagName=="TABLE")
return
while(source.tagName!=highlightbehavior && source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
while (slave.parentNode)
if ((slave = slave.parentNode) == master)
return true;
return false;
}

function changeback(e,originalcolor){
if (ie&&(event.fromElement.contains(event.toElement)¦¦source.contains(event.toElement)¦¦source.id=="ignore")¦¦source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)¦¦source.id=="ignore"))
return
if (ie&&event.toElement!=source¦¦ns6&&e.relatedTarget!=source)
source.style.backgroundColor=originalcolor
}
..............................................................

That shows the "IF" of that function, but i still dont know what you mean about DOM?

slimnutty5000

9:57 pm on Oct 2, 2007 (gmt 0)

10+ Year Member



OK UPDATE on the situation:
Show/Hide function now works in IE.
But TR rollover, slashmenu and image carousel still do not.

Everything still good in Firefox though!

Do you think it can be with my < body onLoad function?

JAB Creations

10:57 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you getting any error messages in Internet Explorer?

- John

Achernar

11:18 pm on Oct 2, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



If you can't decifer IE's error messages - always start with the first one (the one with the lowest line number), and don't try to correct error messages beyond it - , and if you have a working publicly available test page, please send me a sticky mail.

There must be a syntax error somewhere. Is your code only reorganized, or parts have also been deleted?

slimnutty5000

2:55 pm on Oct 3, 2007 (gmt 0)

10+ Year Member



in IE i get a "line 86 syntax error" and "line 95 object expected error".

Line 86 contains:(i included a couple lines before it)

function changeback(e,originalcolor){
if (ie&&(event.fromElement.contains(event.toElement)¦¦source.contains(event.toElement)¦¦source.id=="ignore")¦¦source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)¦¦source.id=="ignore"))
return
if (ie&&event.toElement!=source¦¦ns6&&e.relatedTarget!=source)
source.style.backgroundColor=originalcolor
};

</script> <<<<<<<<<<<Line 86 <<<<<<<<<<<<<<<<

Line 95 contains:(i included a couple lines before it)

<!--START GOOGLE TRACKING-->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1353703-1";
urchinTracker(); <<<<<<<<<<<<Line 95<<<<<<<<<<<<
</script>
<!--END GOOGLE TRACKING-->

I went back to the original javascript source and pasted that over my code again to see if i accidentaly deleted somethign and still no change. I will still keep hacking at it!

Achernar

3:25 pm on Oct 3, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



I've found the main error.

On the ipods page, in the second javascript block (the first being the one with swapimage code), you're opening an html comment but not closing it.
Either close it, or remove the opening tag.

<script type="text/javascript">
<!--
/***********************************************
* Highlight Table Cells

[...]

//-->
</script>

This will solve the problem with the menu.

In the body tag onload attribute you're referencing fillup(). I don't see this function anywhere.

slimnutty5000

3:37 pm on Oct 3, 2007 (gmt 0)

10+ Year Member



FREAKIN A! You solved it! I knew it had to be the simplest thing. Strange thing is that i use Dreamweaver, and i usually go by the code colors, and since all the code was correctly colored i didnt think there was a missing closer or something. And the comment code is grey and the JS is correct color, i wouldnt even think that the comment needed to be closed. But just that little fix fixed the whole damn thing! Your the best! Thanks so much for taking the time to help me out. I REALLY appreciate it.

Achernar

3:38 pm on Oct 3, 2007 (gmt 0)

10+ Year Member Top Contributors Of The Month



:)