PDA

View Full Version : Prompt with a sound


jaywhy13
01-11-2005, 02:35 AM
I have a function in javascript named promptUser(), when this function is called I want it to play a sound.... how would I get that done?

_Aerospace_Eng_
01-11-2005, 03:23 AM
have u attempted the function yet, if so can u post it so we can see it or are you wanting to know how to create such a function

jaywhy13
01-11-2005, 09:35 AM
function promptUser(msg)
{
//If the prompt box calculations have not been made, calculate them
if((xPos==0)&&(yPos==0))
{
xPos=((770-userPrompt.style.pixelWidth)/2);
yPos=((document.body.clientHeight-userPrompt.style.pixelHeight)/2);
}
//Aligning prompt box
userPrompt.style.pixelLeft=xPos;
userPrompt.style.pixelTop=yPos;
//Make it visible
userPrompt.style.visibility="visible"
//Grab the message from the placeholder in function parameter
userPromptmsg.innerHTML=msg;
//Set the clock to time it for 10 seconds then close it
closeTimer=setTimeout("closeUP()",7000);
}


thats the code.... the function opens a popup div and I wanna play a sound when this function is run

thanks

_Aerospace_Eng_
01-12-2005, 10:56 AM
okay i worked something up that is similar to what u have, it is a function that opens a new window centered, and it embeds a sound file, just place this script in between your head tags
<script type="text/javascript">
var win = null;
function promptUser(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable= +r+,statusbar=+s+'
win = window.open(mypage,myname,settings)
document.getElementById("sound").innerHTML="<embed src='http://yoursoundhere.mp3' autostart='true' hidden='true' loop='false'></embed>";
}
</script>
you can call the function any way u choose but u must have an element such as a div or span that has an id that matches the one in the elementbyid in the function so put this somewhere in between ur body tags
<span id="sound'></span>
since the newly opened window opens a page inside it, u can add a selfclosing function to the page that is opened, just add this code in between the head tags
<script>
var length = 10000;

t = null;
function closeMe(){
t = setTimeout("self.close()",length);
}
</script>
the length is measured in milliseconds so 10000 milliseconds is just 10 seconds and to get this to work the right way u will need a body onload code that calls the functions like so
<body onload="closeMe(),self.focus()">
the self.focus brings the new window to the front
to see a working example check out THIS (http://home.austin.rr.com/fairpoolerz/popup.html) page

jaywhy13
01-16-2005, 08:25 AM
Actually what is happening in the code that I wrote above is that I have a Div at the bottom of the page which visibility's property is set to hidden.

And when i need to prompt the user I call upon the div..... set its innerHTML properties and then make it visible so that the user can see the message. And mind you, I have opted to use this method instead of opening a new window because the prompt is apart of the form validation.

But the problem that I have is that there is a slight delay when the user first is prompted because the browser is now given the task of loading the sound for the first time. So in the same way that when we do the "rollover" effect with images, we want it real smooth........

Well thats how I want it to be with the message. One motion, user clicks.... then bam! Display shows, sounds beeps! Thus the need for preloading the sound

Thanks thus far tho!