最近在開發一個網站時,有個需要是 如果有新預警信息要在網頁中播放提示音。頁面打開會請求是否有新信息,有則播放提示音。在Chrome的最新瀏覽器中,播放會報錯,控制台顯示Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.搜索發現Chrome 66為了避免標簽產生隨機噪音禁止沒有交互前使用js進行播放。最后解決方案為 在chrome地址欄輸入chrome://flags/。設置Autoplay policy為No user gesture is required。目前想到的解決方案只有這個了,如果有大神有更好的方案歡迎評論。