php - Play sound when Link Clicked - Stack Overflow

I have written a small web application but am missing some cool functionality. I want to play a sound w

I have written a small web application but am missing some cool functionality. I want to play a sound when the user clicks the link, but after playing the sound continues to navigate to the URL the link points to.

Any ideas?

I have written a small web application but am missing some cool functionality. I want to play a sound when the user clicks the link, but after playing the sound continues to navigate to the URL the link points to.

Any ideas?

Share Improve this question asked Feb 4, 2011 at 5:47 Zac BrownZac Brown 6,09319 gold badges61 silver badges107 bronze badges 1
  • I wonder how this will mesh with IE's similar (mis)feature - the Navigation Completed click. – Piskvor left the building Commented Feb 4, 2011 at 6:46
Add a ment  | 

2 Answers 2

Reset to default 5

While the pursuit of coolness is a worthy ideal, I would strongly remend against playing a sound when a user clicks a link (or at any time!). As both a user and a web developer this would startle me right to the back button. Only several minutes later would I be witty enough to think that I just time traveled to the mid 1990's

EDIT

unless you're going for something retro, like this: (which i highly suspect you aren't)

http://www2.warnerbros./spacejam/movie/jam.htm

EDIT II

Hmm... well I guess a being a game changes things a little. I would remend binding the click event with jquery to append a sound file to the dom, something like this:

$('a').click(function(){
    $('body').append('<embed src="/path/to/your/sound.wav" autostart="true" hidden="true" loop="false">');
    pause(1000);   //Number of milliseconds to pause
    window.location = http://www.asdf. //new url to go to
});
function pause(milliseconds) {
    var dt = new Date();
    while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}

Attach an onclick handler to the link with JavaScript. This function will need to:

  1. Inject or activate a Flash movie or other object capable of playing the audio. JavaScript has no audio-generation abilities itself.

  2. Start a timer to redirect to the link's original location after a suitable delay to load and play the sound. Use window.location to redirect the browser to the URL.

  3. return false to stop the default click action (leaving the page) from occurring too fast for the sound to play.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745220797a4617241.html

相关推荐

  • php - Play sound when Link Clicked - Stack Overflow

    I have written a small web application but am missing some cool functionality. I want to play a sound w

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信