单击链接时播放声音

发布于 2024-10-15 20:16:35 字数 85 浏览 1 评论 0原文

我编写了一个小型网络应用程序,但缺少一些很酷的功能。我想在用户单击链接时播放声音,但播放声音后继续导航到链接指向的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与风相奔跑 2024-10-22 20:16:35

虽然追求酷是一个值得追求的理想,但我强烈建议不要在用户单击链接时(或任何时候!)播放声音。作为用户和网络开发人员,这会让我对后退按钮感到惊讶。仅仅几分钟后,我就会机智地认为我只是时间旅行到了 1990 年代中期的

编辑

,除非你想要复古的东西,就像这样:(我非常怀疑你不是)

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

编辑 II

嗯...好吧我想游戏的存在会改变一些事情。我建议将 click 事件与 jquery 绑定,以将声音文件附加到 dom,如下所示:

$('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.com //new url to go to
});
function pause(milliseconds) {
    var dt = new Date();
    while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}

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:

$('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.com //new url to go to
});
function pause(milliseconds) {
    var dt = new Date();
    while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}
失眠症患者 2024-10-22 20:16:35

使用 JavaScript 将 onclick 处理程序附加到链接。此函数需要:

  1. 注入或激活 Flash 影片或其他能够播放音频的对象。 JavaScript 本身没有音频生成功能。

  2. 启动计时器,在适当的延迟后重定向到链接的原始位置,以加载和播放声音。使用 window.location 将浏览器重定向到 URL。

  3. return false 可阻止默认点击操作(离开页面)发生得太快而导致声音无法播放。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文