SoFunction
Updated on 2025-04-10

How to control the playback and stop of web background music

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS method to control background music bgsound (start and stop)</title>
</head>
 
<body>
<script type="text/javascript">
var bg_sound=document.createElement_x("bgsound");//Create background music
bg_sound.//Set id attribute
(bg_sound);//Add background music in body
//bg_sound.src="tmp3.mp3";
i_bg.src="tmp3.mp3";//Set a background music file
//It should also be written in write, you can try the effect.
function bg_stop(){
  i_bg.src="";
}
function bg_start(){
  i_bg.src="tmp3.mp3";
}
</script>
<span ><a onclick="javascript:bg_stop();" href="javascript:void(0);">Background music stop</a></span>  <span ><a onclick="javascript:bg_start();" href="javascript:void(0);">Background music start</a></span>
</body>
</html>