Gublooo
Gublooo

Reputation: 2618

Embed video javascript code from database in PHP

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

Upvotes: 0

Views: 923

Answers (1)

Walking Wiki
Walking Wiki

Reputation: 699

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.

Upvotes: 0

Related Questions