Search code examples
javascriptpopuppopupwindow

How to play popup sound while displaying popup window


I'm displaying pop up window using the below code:

var left = (screen.width/2)-(400/2);
var top = (screen.height/2)-(400/2);
targetWin2 = window.open ('', 'popup', 'toolbar=no,location=no,directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=10,     top='+top+', left='+left);

It works; but how to play pop up sound while displaying this window?


Solution

  • You can do it with something like this:

    <script langauge="javascript">
    
    var popup="http://www.yahoo.com"
    var alertMessage="This is an alert hehehe"
    
    function userAlert(){
    
    alert(alertMessage)
    document.jukebox.play()
    window.open(popup,"def")
    
    }
    </script>
    
    
    <a href="javascript:userAlert();">Click Here</a>
    
    <embed src='SoundURLHere' autostart='true' hidden='true' loop='true' name="jukebox">
    

    popurl = The page you want to popup

    alertMessage = What you want the alert to say

    SoundURLHere = The Directory to the sound

    there is also the possibility of using vbscript to pop up different types of alert boxes but i dont know if you can then interact with javascript.