簡體   English   中英

瀏覽器不支持音頻時重定向到新頁面

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

我有音頻的JavaScript代碼。 如果瀏覽器支持音頻,我想重定向到URL。 另外,如果瀏覽器不支持音頻,請重定向到另一個鏈接。

我嘗試了這個:

<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>

沒用

有人可以幫忙嗎? 謝謝。

我在一個個人站點上嘗試了此操作,並且也使用了控制台,並且像超級按鈕一樣工作,請嘗試一下,讓我知道它的運行方式。

您已經足夠接近創建和音頻標簽。

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

通用音頻類型值(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