简体   繁体   English

浏览器不支持音频时重定向到新页面

[英]Redirecting to a new page when audio not supported by the browser

I have JavaScript code for audio. 我有音频的JavaScript代码。 I want to redirect to a URL if the browser has audio support. 如果浏览器支持音频,我想重定向到URL。 Also if the browser does not support audio, redirect to another link. 另外,如果浏览器不支持音频,请重定向到另一个链接。

I tried this: 我尝试了这个:

<script>
var audio= document.createElement("audio") 
var media= {audio : (audio.play) ? true : false}

if (media == true) {
    window.location.replace("file1.php");
} else {
    window.location.replace("file2.php");   
}
</script>

It didn't work. 没用

Can anyone help? 有人可以帮忙吗? Thanks. 谢谢。

I tried this on a personal site, and using the console as well, and worked like a charm, give it a try and let me know how it goes. 我在一个个人站点上尝试了此操作,并且也使用了控制台,并且像超级按钮一样工作,请尝试一下,让我知道它的运行方式。

You were close enough creating and audio tag. 您已经足够接近创建和音频标签。

 var audioTest = document.createElement('audio'); if( !!(audioTest.canPlayType && audioTest.canPlayType('audio/mpeg;')) ) { // redirect } else { // redirect } 

Common audio type values (JIC): 通用音频类型值(JIC):

video/ogg
video/mp4
video/webm
audio/mpeg
audio/ogg
audio/mp4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM