0

This is probably a pretty simple thing. I am testing out several video hosting services where I host the videos and use their embed code to display on my site.

Now this embed code is stored in the database and is associated with each topic. So on a given page there could be 20 topics. So when a user clicks on any topic - using ajax I pull the embed code and display it in a given div.

This works fine for the embed code that uses or like in youtube and other services. But there are others that give you a javascript code to embed like shown below

<script type = "text/javascript" id = "vidyard_embed_code_BAKIQxxxxxxxxxxxx">//To resize this video, please login to your dashboard and edit your player settings
(function() { 
    var vidyardcontainer =  document.createElement("div"); 

    vidyardcontainer.id = 'vidyard_BAxxxxxxxxxxx'; 

    var vidyardcontainer_s = document.getElementById('vidyard_embed_code_BAKIQyVKDjg_FeBoGkxr7A');       

    vidyardcontainer_s.parentNode.insertBefore(vidyardcontainer, vidyardcontainer_s);

    var vidyard = document.createElement('script'); 

    vidyard.type = 'text/javascript'; 

    vidyard.async = false; 

    vidyard.src = ('https:' == document.location.protocol ? 'https://secure.' : 'http://embed.') + 'vidyard.com/embed/Bxxxxxxxxxxxxx/iframe/?'; 

    var vidyard_s = document.getElementsByTagName('script')[0]; 

    vidyard_s.parentNode.insertBefore(vidyard, vidyard_s); 

})();  //embedcodev1.0
</script>

So this type of embed code cos its javascript. Is there anyway to get this working. Appreciate your input Thanks

orolo
  • 3,951
  • 2
  • 30
  • 30
Gublooo
  • 2,550
  • 8
  • 54
  • 91
  • If I understood you want to run this js from an ajax call, right? Maybe this will help you: http://stackoverflow.com/questions/235967/calling-a-jquery-function-inside-html-return-from-an-ajax-call –  Sep 30 '11 at 16:18

1 Answers1

0

JQuery does a lot of crazy stuff with script tags. It's not terribly well documented, but some methods like .html(data) will strip them out. The ajax methods also do some crazy evaluation magic.

This answer may come too late, but at least for the Vidyard case you can use the alternative iframe embed code. Click the checkbox in the embed area that says Using Tumblr, Posterous, or just having trouble embedding? Try our fallback code to get it.

Walking Wiki
  • 699
  • 4
  • 13