我为公共(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/