Placing a dynamic YouTube video in an iframe (asp.net)

1

Good evening! I'm trying to put a youtube video based on a url stored in a sql database, the problem is that the way I found it to put, works only with some static url, in the following way:

<iframe width="560" height="315" src="https://www.youtube.com/embed/o_l4Ab5FRwM"frameborder="0" allowfullscreen></iframe>

I'm trying to put a variable value for src, I thought of a label and then assign it in .Text, but it does not work because the Iframe for when I insert the label in the middle of it ... does anyone have an idea of what I can do? / p>

Thanks: D

    
asked by anonymous 18.05.2016 / 02:41

1 answer

1

Is this variable server-side or client-side? In these cases you have two solutions:

Example 1: Use the src attribute of the iframe.

// Captura elementos iframe, pode utilizar o método getElementById
var iframe = document.getElementsByTagName("iframe");
iframe[0].src = "https://www.youtube.com/embed/o_l4Ab5FRwM";
<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>

Example 2 : Building the iframe dynamically via javascript.

var iframe2 = document.createElement("iframe");
iframe2.src = "https://www.youtube.com/embed/o_l4Ab5FRwM";
iframe2.width = 560;
iframe2.height = 315;
iframe2.frameborder = 0;
iframe2.allowfullscreen = true;
document.body.appendChild(iframe2);
    
18.05.2016 / 04:55