I have this code and I do not know why it does not work
<html> <head> <title>Test</title> <script type="text/javascript"> function StopBackgroundMusic() { var MusicObj = document.getElementById("BackgroundMusic"); MusicObj.data = "http://www.oreillynet.com/examples/oreilly/digitalmedia/2005/02/ableton_intro_0205_gtr.mp3"; MusicObj.autoplay = "false"; MusicObj.autostart = "false"; return MusicObj; } </script> </head> <body> <OBJECT ID="BackgroundMusic" data="http://www.oreillynet.com/examples/oreilly/digitalmedia/2005/02/ableton_intro_0205_gtr.mp3" TYPE="audio/mpeg" height="0" width="0"> <PARAM NAME="autostart" VALUE="true"> <PARAM NAME="autoplay" VALUE="true"> </OBJECT> <form> <input type='button' onclick='StopBackgroundMusic()' value='Stop music'/> </form> </body> </html>
Try nullsetting the data to instead of setting the music URL again.
null
Another alternative is to remove the node object when you click the stop button:
function StopBackgroundMusic() { var MusicObj = document.getElementById("BackgroundMusic"); MusicObj.parentNode.removeChild(MusicObj); }
Is the "BackgroundMusic" element enclosed in a form element? if so try things like this
document.getElementById("[formID].BackgroundMusic");
if you use a form tag, specify its id,
<form id="music">
Source: https://habr.com/ru/post/1789814/More articles:Связь между веб-приложением Rails и приложением Mac - ruby-on-railsDisconnect blocking from another thread than the owner of the monitor - multithreadingString management - any other efficient way? - javaelmah on the IIS 6 drawer - elmahFind the intersection of 2 curves & the area under the curve to the right of the intersection w / Mathematica - wolfram-mathematicaProblem with delegate and navigation controller - objective-cPHP / MySQL> Refresh field when clicking a link - javascriptASP.NET MVC 3 - Client Validation with a Money Field - asp.net-mvc-3WCF service stops to create threads - multithreadingCapture Modal Dialog Object Using MSHTML / IExplorer - c #All Articles