your variable audioWindow is declared in the scope of audioOnOff. That means it only exists for the length of time that function is running so by the time you get to calling stopAudio is is no longer the same instance of the variable and doesn't correspond to the opened window.
I would also not declare playAudio and stopAudio inside audioOnOff so I would declare it this as
Code: ( text )
var audioWindow;
function playAudio()
{
audioWindow = window.open(audioFile, "_blank");
}
function stopAudio()
{
audioWindow.close();
}
function audioOnOff(audioFile, playButton, stopButton)
{
playButton.attachEvent("onclick", playAudio);
stopButton.attachEvent("onclick", stopAudio);
}
You may also need to do something for the case of the user clicking a play button when a window is already open as you will end up with 2 windows open but audioWindow will only refer to the last window opened.