如何通过查询字符串更改youtube嵌入代码中URL的一部分
本文关键字:代码 URL 一部分 youtube 查询 何通过 字符串 | 更新日期: 2024-10-23 05:17:57
我正在用C#在ASP.NET上编程。我想知道如何通过查询字符串更改youtube嵌入代码中URL的一部分。例如
<iframe width="560" height="315" src="http://www.youtube.com/embed/**5CZobYTEwaY**" frameborder="0" allowfullscreen></iframe>
我想通过查询字符串接收视频的变量并插入,而不是5CZobYTEwaY。
如果有人帮助我,我将不胜感激。
请用下面的代码替换查询字符串variable"id"下面的示例使用test.asp?id=5CZobYTEwaY
<iframe width="560" height="315" src='http://www.youtube.com/embed/<%=Request.QueryString["id"]%>' frameborder="0" allowfullscreen></iframe>
您可以使用<asp:Literal
在页面上输出一个干净的字符串。
试试这个:
<iframe width="560" height="315" src="http://www.youtube.com/embed/<asp:Literal ID="keyOfVideo" runat="server"></asp:Literal>" frameborder="0" allowfullscreen></iframe>
CodeBehind:
keyOfVideo.Text = "SomeKey";
您可以为iframe添加属性,同时将其设置为在服务器上运行。
example = "5CZobYTEwaY";
ex_iframe.Attributes.Add("src", "http://www.youtube.com/embed/" + example);