javascript - 在触摸屏上添加声音

标签 javascript audio indexof

我为公共(public)触摸屏制作了一个应用程序。我必须在每个部分的第一页插入声音/语音来帮助用户。
我在 Url 上使用 indexOf 函数。但我想要第一页上的声音。

例如“信息”页面,
我有我的url : "[...]index.php?state=information" .所以我用window.location.href.indexOf(«state=information»)在 JS 中:

function playSounds(){

        var obj = document.createElement('audio');
        obj.volume=0.10;
        obj.autoPlay=false;
        obj.preLoad=true;     
        …
        var information = "state=information";
        …
        if (window.location.href.indexOf(information) > -1){
            obj.src="/sounds/Menu_information.wav";
            obj.play();
        }
        …
}

但从逻辑上讲,当 url 为 "[...]index.php?state=information&pageinfo=2" 时,语音也会播放。例如。

但也许我一切都错了......
有什么其他方法或功能可以将声音放在每个部分的主页上而不重复?

先感谢您,
埃维。

最佳答案

只需检查附加参数 &pageinfo=2 .

var url = 'index.php?state=information&pageinfo=2';    
var matches = url.match(/[a-z\d]+=[a-z\d]+/gi);
    var count = matches? matches.length : 0;
    if( count == 1 )
      // play the sound
    else
      return false;

试试这个(:

干杯。

关于javascript - 在触摸屏上添加声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40802765/

相关文章:

javascript - jquery ajax - 调整另一个页面的 iframe 的大小

java - 在 Java 中使用 indexOf() 查找对象 arrayList 的索引值

javascript - 从网站上给定 SKU 编号列表中提取产品名称的最佳方法是什么?

python - 检测音频信号中的数字削波

flash - 在 Flash 9、Actionscript 3 中播放短声音的延迟

android - Tarsos WriterProcessor不产生输出内容

javascript - 如何使用indexOf()来检查数组中的字符串是否部分匹配另一个数组中的字符串?

javascript - 哪一个更快? `array.findIndex` 与 `array.reduce` + `object[index]`

javascript - 使用 lodash 将对象转换为数组

javascript - 如何使用 JavaScript 或 jQuery 将样式表中 CSS 类的属性直接加载到散列中?