SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I create a delay to new location onclick link script?

    How do I create a delay to new location onclick link script?

    Hi
    I wish to create an onclick delay for my page links. I wish to do this because I have a site in which I would like to have all the links have a sound indication giving the user feedback that he made the click. I wrote a little code to test the concept. It worked well usually in Firefox however it failed to work in Internet Explorer. I believe the reason is that Internet Explorer moved to the new location before the sound had a chance to play. I believe this because in my little demonstration code when I do not link a link to a new location I hear the indication sound just fine. However when I link to a new location it appears I get to this new location before the sound has a chance to play. The press in sound is of short duration but is not the sound I would ultimately use is just a test sound. My little demonstration script and HTML code appears below a long with a link to my demonstration page. If it would be possible to get some help writing a script that would degrade gracefully if JavaScript was turned off I would be very appreciative. However I may be able to figure out the degrade gracefully part myself if I could get some suggestions on how I go about learning to write this script or just get it here. Tell me what you can. Here is the script, HTML, and link.

    JavaScript
    Code:
    function eventSound() {
      var thissound=document.getElementById("sound1");
      thissound.Play();
    }
    function allAanchor(){
    var anchors = document.getElementsByTagName("a");
     for (var i=0; i < anchors.length; i++)
             anchors[i].onclick=eventSound; 
    }
    
    window.onload = function () {
    allAanchor();
     }
    Code:
    HTML
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <meta content="text/html; charset=us-ascii"
     http-equiv="Content-Type" />
    <title>yyyl</title>
    <script src="yyyl.js" type="text/javascript"></script>
    </head>
    <body>
    <embed src="success.wav" autostart=false 
    width=0 height=0 id="sound1" enablejavascript="true">
    <p>&nbsp;&nbsp;
        <a href="under constructionYyyl.html">
            link to under construction location
        </a>
        <br><br><br>&nbsp;&nbsp;
        <a href="#">
            link with out new location
        </a>
        <br><br><br>&nbsp;&nbsp; 
        <a href="under constructionYyyl.html">
            link to under construction location
        </a>
        <br><br><br>&nbsp;&nbsp;
          <a href="#">link with out new location
        </a>
        <br><br><br>&nbsp;&nbsp; 
    </p>
    </body>
    </html>
    link to concept demonstration page

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    To delay something with javascript, use the setTimeout() function: http://developer.mozilla.org/en/docs...dow.setTimeout

    Do you really need to do this, though? Be aware that anything that is a surprise to the user is an annoyance. Especially when it comes to sound. Flash movies that play sound immediately once they have loaded without the user choosing this annoy the hell out of me (and many others I'm willing to bet). The same would go for a link that plays a sound without warning me. And even if it does warn me, I would still dislike it, especially if it doesn't give me the option of turning this off.

    Also, be aware that <embed> is deprecated in favour of <object>. The second post on this page is quite useful: http://forums.htmlhelp.com/index.php?showtopic=607

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fear you misunderstand. This desire for sound originates from an other part of the page it is intended for. As of now I have just used a popping sound in my demonstration page but the idea is to create a click as an extra indication that you have selected the link. That is done to be consistent with another part of the page which has an update window controlled by buttons. This window gives you feedback on the status of a slideshow whether the slides are changing at every five seconds or every 30 seconds and so on. I wish to give a click because somebody might not be aware that something has changed with inside the status window when one clicks the faster or slower buttons. So the sound is only intended to be a quick click as soon as you engage the link to be consistent with the window status part of the page.

    I am quite aware that the setTimeout() function creates a delay and have used it several times however this is something different. The delay I wish to create is a delay in the HTML link. I was thinking I have to overwrite the link target location somehow and then do something like rewrite it to be active a split second later just to give my click some time to sound. However I do not know how to do this. Just have the vague idea I have just mentioned.


Bookmarks

Posting Permissions

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