我制作了一个带有弹出窗口的chrome扩展,其中包含一个按钮,当按下该按钮时,应播放声音。但是,按下按钮时不会播放声音。 javascript文件:
function playAudio(audioElementId)
{
document.getElementById(audioElementId).play()
}
html文件:
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="MainScript.js"></script>
<link rel="stylesheet" type="text/css" href="MainCSS.css" />
<title></title>
</head>
<body>
<audio id="AudioFile" src="sound.wav"></audio>
<button id="soundButton" onclick="playAudio('AudioFile')">Play Sound</button>
</body>
</html>
清单json文件:
{
"manifest_version": 2,
"name": "Play A Sound",
"description": "plays a sound when button is pressed",
"version": "1.0",
"browser_action": {
"default_popup": "index.html"
},
"permissions": [
"activeTab",
"tabs",
"notifications",
"background",
"https://ajax.googleapis.com/"
]
}