Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I have a link play sound and then redirect?

    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....

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Code:
    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
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by martin_narg
    Code:
    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:

    Code:
    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?

  • #4
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Code:
    function playSound(soundobj, linkurl) {
      document.getElementById(soundobj).Play();
      var mySoundTime = 1000; // length of sound in milliseconds
      setTimeout("document.location="+linkurl, mySoundTime);
    }
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The Play() function I believe only works in IE fyi.

  • #6
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by martin_narg
    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •