...

View Full Version : How do I have a link play sound and then redirect?



djchicago
07-07-2005, 05:14 PM
I have a set of links on my site, and I would like to use javascript to play a sound when they are clicked, and then direct the browser to a new page. I've been able to get the javascript redirect and the sound to work independently of each other, but not together. Invariably, one of them works and one does not. Does anybody know how to write a script to do both? Thanks....

martin_narg
07-07-2005, 05:19 PM
function playSound() {
// .... play sound code here
var mySoundTime = 3000; // length of sound in milliseconds
setTimeout("document.location='myRedirectPage.html'", mySoundTime);
}


hope this helps

m_n

djchicago
07-07-2005, 08:02 PM
function playSound() {
// .... play sound code here
var mySoundTime = 3000; // length of sound in milliseconds
setTimeout("document.location='myRedirectPage.html'", mySoundTime);
}


hope this helps

m_n

Thanks.... It's working great, except for one thing: I want the URL to be a variable, passed to the function like the sound. See below:



function playSound(soundobj, linkurl) {
var thissound=document.getElementById(soundobj);
thissound.Play();
var mySoundTime = 1000; // length of sound in milliseconds
setTimeout("document.location=linkurl", mySoundTime);
}


I'm getting errors telling me that linkurl is "undefined", which I assume means I didn't insert it correctly into the code..... I know the function call is correct.

Any ideas?

martin_narg
07-07-2005, 08:13 PM
function playSound(soundobj, linkurl) {
document.getElementById(soundobj).Play();
var mySoundTime = 1000; // length of sound in milliseconds
setTimeout("document.location="+linkurl, mySoundTime);
}

_Aerospace_Eng_
07-07-2005, 08:15 PM
The Play() function I believe only works in IE fyi.

djchicago
07-07-2005, 08:51 PM
function playSound(soundobj, linkurl) {
document.getElementById(soundobj).Play();
var mySoundTime = 1000; // length of sound in milliseconds
setTimeout("document.location="+linkurl, mySoundTime);
}


When I make this change, I get an error saying that I'm missing a semicolon at "line 1, character 23", and the script doesn't work.... no idea why.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum