...

View Full Version : OnClick Doesn't Work In Internet Explorer 6



JeStEr
07-29-2002, 07:34 AM
The following javascript only works in Netscape. It doesn't work in Internet Explorer 6, it keeps giving me errors. Is there anything i can do that would fix the javascript and make in compatible with all netscape and internet explorer browsers?

<HTML>
<HEAD>
<TITLE>Untitled</TITLE>

<SCRIPT LANGUAGE=JavaScript>
<!--
timer=""
whereto=new Array()
whereto[whereto.length]="http://www.yahoo.com"
whereto[whereto.length]="http://www.google.com"
whereto[whereto.length]="http://www.huntingground.net"
whereto[whereto.length]="http://www.microsoft.com"
whereto[whereto.length]="http://www.freeserve.co.uk"
whereto[whereto.length]="http://www.yahoo.com"

function playSound(name,where){
clearTimeout(timer)
document.embeds[name].play();
here=where
timer=setTimeout("document.location=whereto[here]",1000)
}
// -->
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript>
<!--
timer=""
whereto1=new Array()
whereto1[whereto.length]="http://www.yahoo.com"

function playSound1(name,where){
clearTimeout(timer)
document.embeds[name].play();
here=where
timer=setTimeout("document.location=whereto1[here]",6000)
}
// -->
</SCRIPT>

</HEAD>

<BODY>

<EMBED SRC="sounds/sound1.wav" autostart=false HIDDEN=TRUE NAME="music1" MASTERSOUND width="128" height="128">
<EMBED SRC="sounds/sound2.wav" autostart=false HIDDEN=TRUE NAME="music2" MASTERSOUND width="128" height="128">
<a href="#null" onclick="playSound('music1','0');return false" ><IMG SRC="pictures/pic1.jpg"></a>
<a href="#null" onclick="playSound('music1','1');return false" ><IMG SRC="pictures/pic2.jpg"></a>
<a href="#null" onclick="playSound('music1','2');return false" ><IMG SRC="pictures/pic3.jpg"></a>
<a href="#null" onclick="playSound('music1','3');return false" ><IMG SRC="pictures/pic4.jpg"></a>
<a href="#null" onclick="playSound('music1','4');return false" ><IMG SRC="pictures/pic5.jpg"></a>
<a href="#null" onclick="playSound('music1','5');return false" ><IMG SRC="pictures/pic6.jpg"></a>
<a href="#null" onclick="playSound1('music2','6');return false" ><IMG SRC="pictures/pic7.jpg"></a>

</BODY>
</HTML>

WebKunstler
07-29-2002, 08:01 AM
but if you change your "onclick" to "onClick", you might just have an all-round working script...

JeStEr
07-29-2002, 08:23 AM
I tried what you said, but it still didn't work. i still get an error in internet explorer 6. are there any other suggestions how i could make this script compatible with all netscape and internet explorer browsers, especially IE6.

glenngv
07-29-2002, 08:26 AM
you didn't mention what error msg is displayed in IE6


Originally posted by JeStEr
I tried what you said, but it still didn't work. i still get an error in internet explorer 6. are there any other suggestions how i could make this script compatible with all netscape and internet explorer browsers, especially IE6.

joh6nn
07-29-2002, 09:17 AM
i'm surprised that it works in netscape.

i think you've got a couple of problems. try the following, and let me know how it works:


<HTML>
<HEAD>
<TITLE>Untitled</TITLE>

<SCRIPT LANGUAGE=JavaScript><!--
timer, here, whereto = ["http://www.yahoo.com","http://www.google.com","http://www.huntingground.net","http://www.microsoft.com","http://www.freeserve.co.uk","http://www.yahoo.com"];

function playSound(name,where){
clearTimeout(timer);
document.embeds[name].play();
here = where;
timer = setTimeout("window.location = whereto[here]",1000) ;
}
//--></SCRIPT>

</HEAD>

<BODY>

<EMBED SRC="sounds/sound1.wav" autostart=false HIDDEN=TRUE NAME="music1" MASTERSOUND width="128" height="128">
<EMBED SRC="sounds/sound2.wav" autostart=false HIDDEN=TRUE NAME="music2" MASTERSOUND width="128" height="128">
<a href="javascript:playSound('music1','0'); void 0;"><IMG SRC="pictures/pic1.jpg"></a>
<a href="javascript:playSound('music1','1'); void 0;"><IMG SRC="pictures/pic2.jpg"></a>
<a href="javascript:playSound('music1','2'); void 0;"><IMG SRC="pictures/pic3.jpg"></a>
<a href="javascript:playSound('music1','3'); void 0;"><IMG SRC="pictures/pic4.jpg"></a>
<a href="javascript:playSound('music1','4'); void 0;"><IMG SRC="pictures/pic5.jpg"></a>
<a href="javascript:playSound('music1','5'); void 0;"><IMG SRC="pictures/pic6.jpg"></a>
<a href="javascript:playSound('music2','6'); void 0;"><IMG SRC="pictures/pic7.jpg"></a>

</BODY>
</HTML>

glenngv
07-29-2002, 09:26 AM
to play sound in IE you need <bgsound> tag not <embed> tag.
then you just set the .src property of the sound object to play it and set to empty to stop.

joh6nn
07-29-2002, 09:41 AM
no, ie will take embed. i don't know if netscape will take bgsound, though.

glenngv
07-29-2002, 10:00 AM
Originally posted by joh6nn
no, ie will take embed. i don't know if netscape will take bgsound, though.

http://codingforums.com/showthread.php?threadid=2900

JeStEr
07-29-2002, 06:22 PM
when i used the code above you gave me it wouldn't play the sound or link to the correct websites in IE6 or netscape.

i'm thinking it's my IE6, but i'm not positive it is, because i tried the first code that i used (the first post) and it worked in IE5.5 on a different computer.

when i use my code (the first post) the error message that i receive in IE6 is "a runtime error has occured, do you wish to debug?"

are there any suggestions on how to fix this, remember i need the javascript to be able to work on all netscape and all IE browsers.

JeStEr
07-29-2002, 06:53 PM
maybe is it possible to have the first code (first post) written two times, one specifically for all netscape browsers and one specifically for all IE browsers, would that work?

joh6nn
07-29-2002, 10:34 PM
the following code works for me in Internet Explorer. my copy of mozilla complains that "document.embeds[name].play();" is not a method. i'm guessing this means there's a netscape/mozilla specific method to make things play. i don't know what it is. however, the part about changing to the new url still works in mozilla.


<HTML>
<HEAD>
<TITLE>Untitled</TITLE>

<SCRIPT LANGUAGE=JavaScript><!--
var timer = false, here, whereto = ["http://www.yahoo.com","http://www.google.com","http://www.huntingground.net","http://www.microsoft.com","http://www.freeserve.co.uk","http://www.yahoo.com"];

function playSound(name,where){
if (timer != false) {
clearTimeout(timer);
}
document.embeds[name].play();
here = where;
timer = setTimeout("window.location = whereto[here]",1000);
}
//--></SCRIPT>

</HEAD>

<BODY>

<EMBED SRC="sounds/sound1.wav" autostart="false" HIDDEN=TRUE NAME="music1" MASTERSOUND width="128" height="128">
<EMBED SRC="sounds/sound2.wav" autostart=false HIDDEN=TRUE NAME="music2" MASTERSOUND width="128" height="128">
<a href="javascript:playSound('music1','0'); void 0;"><IMG SRC="pictures/pic1.jpg" width="10" height="10" alt=""></a>
<a href="javascript:playSound('music1','1'); void 0;"><IMG SRC="pictures/pic2.jpg" width="10" height="10" alt=""></a>
<a href="javascript:playSound('music1','2'); void 0;"><IMG SRC="pictures/pic3.jpg" width="10" height="10" alt=""></a>
<a href="javascript:playSound('music1','3'); void 0;"><IMG SRC="pictures/pic4.jpg" width="10" height="10" alt=""></a>
<a href="javascript:playSound('music1','4'); void 0;"><IMG SRC="pictures/pic5.jpg" width="10" height="10" alt=""></a>
<a href="javascript:playSound('music1','5'); void 0;"><IMG SRC="pictures/pic6.jpg" width="10" height="10" alt=""></a>
<a href="javascript:playSound('music2','6'); void 0;"><IMG SRC="pictures/pic7.jpg" width="10" height="10" alt=""></a>

</BODY>
</HTML>

JeStEr
07-31-2002, 07:55 PM
thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum