admin管理员组文章数量:1287984
I'm trying to embed a video on my page via a javascript property :
value: "<iframe title='YouTube video player' type=\"text/html\" width='640' height='390 src=''frameborder='0' allowFullScreen></iframe>"
But when I display this value within the browser the text is displayed instead of the youtube video :
I'm trying to embed a video on my page via a javascript property :
value: "<iframe title='YouTube video player' type=\"text/html\" width='640' height='390 src='http://www.youtube./embed/W-Q7RMpINVo'frameborder='0' allowFullScreen></iframe>"
But when I display this value within the browser the text is displayed instead of the youtube video :
Share Improve this question edited Feb 27, 2014 at 10:59 Java_User 1,3213 gold badges27 silver badges38 bronze badges asked Feb 27, 2014 at 10:56 blue-skyblue-sky 53.9k159 gold badges465 silver badges780 bronze badges 3- 3 How do you add this property/value to the HTML document? – Flixer Commented Feb 27, 2014 at 10:59
- 1 Need to see more of your code..looks like you're missing a script tag or something of the sort.. – Dory Zidon Commented Feb 27, 2014 at 11:00
- I cant help but wonder why you're doing this? – Alex Commented Feb 27, 2014 at 11:01
4 Answers
Reset to default 3You can use two options that are shared here:
use
document.write
:var obj = {"video": { "value": "<iframe title='YouTube video player' type=\"text/html\" width='640' height='390' src='http://www.youtube./embed/W-Q7RMpINVo' frameborder='0' allowFullScreen></iframe>" }} document.write(obj.video.value);
DEMO
Use Div and append html using jQuery:
var obj = {"video": { "value": "<iframe title='YouTube video player' type=\"text/html\" width='640' height='390' src='http://www.youtube./embed/W-Q7RMpINVo' frameborder='0' allowFullScreen></iframe>" }} $("#test").html(obj.video.value); <div id="test"></div>
DEMO
This works for me:
<script>
document.write("<iframe title='YouTube video player' type=\"text/html\" width='640' height='390' src='http://www.youtube./embed/W-Q7RMpINVo'frameborder='0' allowFullScreen></iframe>";
</script>
Btw.: You missed a '
caracter after the height='390
.
If you have a specific part of the page, you can add via id or class... id being the simplest... e.g. to insert in a div with id of header:
<script>
document.getElementById('header').innerHTML = "<iframe title='YouTube video player' type=\'text/html\' width='640' height='390' src='http://www.youtube./embed/W-Q7RMpINVo' frameborder='0' allowFullScreen></iframe>"
</script>
Use a div
tag with id
say panel
.
Then append this value using jquery like this: $('div#panel').html('[obj.value]');
.
本文标签: jqueryEmbedding a youtube video on page using javascriptStack Overflow
版权声明:本文标题:jquery - Embedding a youtube video on page using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741333349a2372894.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论