Click here to Skip to main content
15,895,813 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change SRC and of object tag
it works in firefox but not in Chrome and IE
JavaScript
<script>
 function VideoLoad() {
            var VideoId = $(element).attr('value');
           
            $("#param").attr('value', 'http://www.youtube.com/v/9dLPOpOtKQE?version=3&hl=en_GB');

            $("#embed").attr('src', 'http://www.youtube.com/v/9dLPOpOtKQE?version=3&hl=en_GB');
           
           
        }

<script>
<pre lang="xml"></pre>
<body>
  <img class="ImgSlide GrayShd"  onclick="VideoLoad()" src="http://img.youtube.com/vi/8Csk8lMfQnA/1.jpg" />

  <object width="450" height="420">
                                        <param name="movie" id="param" value="http://www.youtube.com/v/8Csk8lMfQnA?hl=en_GB&amp;version=3">
                                        </param>
                                        <param name="allowFullScreen" value="true"></param>
                                        <param name="allowscriptaccess" value="always"></param>
                                        <embed id="embed" src="http://www.youtube.com/v/8Csk8lMfQnA?hl=en_GB&amp;version=3"
                                            type="application/x-shockwave-flash" width="450" height="420" allowscriptaccess="always"
                                            autostart="true" allowfullscreen="true"></embed></object>
</body>
Posted
Comments
ZurdoDev 2-Apr-13 7:16am    
Have you used the developer tools in the browsers where it doesn't work?
Member-515487 2-Apr-13 7:20am    
yes but its was shown any error this code works for Firefox
Sandeep Mewara 2-Apr-13 10:01am    
What error?
Member-515487 3-Apr-13 2:52am    
there was no no error in code because src and value getting change i hv check with alert but Object tag not getting refresh it work properly with Mozilla
Member-515487 2-Apr-13 7:24am    
it also work if i use c# method to do but not with script

1 solution

Try this below code, Hope it helps you.

HTML
<html>
<head></head>
<body>

<div id="player">

<object width="640" height="360">
  <param name="movie" value="https://www.youtube.com/v/Zhawgd0REhA?version=3"></param>
  <param name="allowFullScreen" value="true"></param>
  <param name="allowScriptAccess" value="always"></param>
  <embed src="https://www.youtube.com/v/Zhawgd0REhA?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed>
</object>

</div>
<a href="#"  önclick="changevideo('oKiYuIsPxYk')"> HTY dargon</a>
<a href="#"  önclick="changevideo('q6uoyPTcfic')"> despicable me 2</a>

<script>
function changevideo(id)
{
   
	var divObj = document.getElementById('player');
	divObj.innerHTML = '<object width="640" height="360">'+
		  '<param name="movie" value="https://www.youtube.com/v/'+ id + '?version=3"></param>' +
		  '<param name="allowFullScreen" value="true"></param>'+
		  '<param name="allowScriptAccess" value="always"></param>'+
		  '<embed src="https://www.youtube.com/v/'+id+'?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed>'+
		'</object>';
}
</script>

</body>
</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900