单击链接时播放声音
我编写了一个小型网络应用程序,但缺少一些很酷的功能。我想在用户单击链接时播放声音,但播放声音后继续导航到链接指向的 URL。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然追求酷是一个值得追求的理想,但我强烈建议不要在用户单击链接时(或任何时候!)播放声音。作为用户和网络开发人员,这会让我对后退按钮感到惊讶。仅仅几分钟后,我就会机智地认为我只是时间旅行到了 1990 年代中期的
编辑
,除非你想要复古的东西,就像这样:(我非常怀疑你不是)
http://www2.warnerbros.com/spacejam/movie/jam.htm
编辑 II
嗯...好吧我想游戏的存在会改变一些事情。我建议将 click 事件与 jquery 绑定,以将声音文件附加到 dom,如下所示:
While the pursuit of coolness is a worthy ideal, I would strongly recommend 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.com/spacejam/movie/jam.htm
EDIT II
Hmm... well I guess a being a game changes things a little. I would recommend binding the click event with jquery to append a sound file to the dom, something like this:
使用 JavaScript 将 onclick 处理程序附加到链接。此函数需要:
注入或激活 Flash 影片或其他能够播放音频的对象。 JavaScript 本身没有音频生成功能。
启动计时器,在适当的延迟后重定向到链接的原始位置,以加载和播放声音。使用
window.location
将浏览器重定向到 URL。return false
可阻止默认点击操作(离开页面)发生得太快而导致声音无法播放。Attach an onclick handler to the link with JavaScript. This function will need to:
Inject or activate a Flash movie or other object capable of playing the audio. JavaScript has no audio-generation abilities itself.
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.return false
to stop the default click action (leaving the page) from occurring too fast for the sound to play.