我想在浏览器打开网页时自动播放mp3文件。这是我基于jQuery的javascript代码:
$(window).load(function(){
alert("Hey");
(new Audio('mp3/musik.mp3')).play();
});
Android上的Chrome是Google Play商店(50.0.something)的最新版本,在我的笔记本电脑上是44.0.2403.157(Ubuntu 15.10 64位)。
在两个浏览器中都显示弹出窗口,但mp3仅在我的笔记本电脑上播放。如果onclick事件执行相同的代码(匿名函数中的代码),则它可以在两个设备上运行。这没有意义,是吗?地狱到底哪里来了?
提前致谢!
答案 0 :(得分:1)
感谢@JohnSmith对我的问题评论中的anser:
我认为不支持自动播放HTML5音频Chrome Android。
答案 1 :(得分:0)
.load可能会失败,请参阅http://api.jquery.com/load-event/
使用document .ready代替:
#content .articlehs h3 {
margin-top: 0px;
font-family: 'New Rocker', cursive;
background: url("../img/article_head.png") repeat-x;
border: 2px solid background: url("../img/asbg.png") repeat-x;
padding: 10px 20px;
}
#content .articlehs p {
background: url("../img/asbg.png") repeat-x;
padding: 10px 20px 20px;
}
#content .articlehs {
display: inline-block;
background: url("../img/asbg.png") repeat-x;
width: 50%;
margin-left: 10%;
margin-top: 10px;
}
#content .articleSidebar h3 {
margin-top: 0px;
font-family: 'New Rocker', cursive;
background: url("../img/article_head.png") repeat-x;
border: 2px solid background: url("../img/asbg.png") repeat-x;
padding: 10px 20px;
}
#content .articleSidebar p {
background: url("../img/asbg.png") repeat-x;
padding: 10px 20px 20px;
}
#content .articleSidebar {
display: inline-block;
background: url("../img/asbg.png") repeat-x;
width: 20%;
margin-left: 10%;
margin-top: 40px;
}
答案 2 :(得分:0)
这有用吗?
$message .= $POST['form']
让我知道这是否有效。
<强>更新强>
好的,我已经尝试了这个并且有效
$(document).ready(function(){ });
希望这能解决你的问题。