找到youtube iframe并将其替换为自定义代码(Find youtube iframe and replace it with custom code)
我有一个wp网站,在很多帖子中我使用youtube视频嵌入了clasic iframe。 可以在帖子中找到iframe div并用自定义的youtube代码替换它吗? 我想使用下面的代码来控制youtube视频。 它何时启动,何时完成。
我在帖子中的代码是:
<iframe width="824" height="464" src="//www.youtube.com/embed/eEqIBzxHjiA?rel=0" frameborder="0" allowfullscreen></iframe>
我想用以下代替:
<script> // create youtube player var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { height: '390', width: '640', videoId: 'eEqIBzxHjiA', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); } // autoplay video function onPlayerReady(event) { event.target.playVideo(); } // when video ends function onPlayerStateChange(event) { if(event.data === 0) { alert ('FInished'); } } </script>
感谢你们...
I have a wp site that in a lot of posts i am using youtube videos embeded with the clasic iframe. Is possible to find the iframe div inside post and replace it with a custom youtube code? I want to use the code bellow to control youtube video. When it starts, when it is finished.
The code that i have in my posts is:
<iframe width="824" height="464" src="//www.youtube.com/embed/eEqIBzxHjiA?rel=0" frameborder="0" allowfullscreen></iframe>
And i want to replace it with:
<script> // create youtube player var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { height: '390', width: '640', videoId: 'eEqIBzxHjiA', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); } // autoplay video function onPlayerReady(event) { event.target.playVideo(); } // when video ends function onPlayerStateChange(event) { if(event.data === 0) { alert ('FInished'); } } </script>
Thank you guys...
满意答案
使用短代码 1. WordPress Rich Editor可能会删除JavaScript src标签,所以最好是编写一个定义短代码的小插件,例如[myyoutube id = eEqIBzxHjiA]并从现在开始使用它。 您可能希望定义一个包含主要代码的javascript .js文件,并将其包含在存在短代码的每个页面中。 因此除了播放器ID之外的所有上述内容都将在您在快捷键代码中定义的包含的.js文件中。 只有playerId才是对javascript函数的调用。
遗产 2.对于所有现有条目:可能最快在数据库帖子表上使用sql命令,并将与上述正则表达式匹配的所有条目替换为新的短代码标记。 (最快的方式)
use shortcodes 1. The WordPress Rich Editor might strip out JavaScript src tags so best is to write a little plugin that defines a shortcode e.g. [myyoutube id=eEqIBzxHjiA] and use that one from now on. Probably you want to define a javascript .js file that holds the main code and include that in each page where the shortcode is present. So all of the above except the player ID will be in the included .js file that you define in the shortcut code. only the playerId is then a call to the javascript function.
legacy 2. For all the existing entries: probably the fastest to use a sql command on the database posts table and replace all entries matching the regex above with the new shortcode tag. (fastest way)
相关问答
更多Youtube iframe wmode问题(Youtube iframe wmode issue)
iframe上的youtube无效(youtube on iframe is not working)
验证/允许YouTube嵌入代码(Validating/Allowing YouTube Embed Code)
到iframe的Youtube网址(Youtube URL to Iframe)
找到刚刚使用Youtube API完成播放的Youtube iframe的父div(Find the parent div of the Youtube iframe that just finished playing using Youtube API)
通过javascript为YouTube流聊天iframe自定义CSS样式(Custom CSS style for YouTube Stream Chat iframe via javascript)
将YouTube观看替换为嵌入视频的
将?enablejsapi = 1添加到YouTube iframe代码(Adding ?enablejsapi=1 to YouTube iframe Code)
在iframe中更改youtube缩短的网址值(Change youtube shortened url value in iframe)
找到youtube iframe并将其替换为自定义代码(Find youtube iframe and replace it with custom code)
相关文章
更多如何获取iframe刷新后的内容
div 与 iframe页面缩小问题 [JavaScript]
javascript replace 连续用两次的问题
如何向一个页面中的两个iframe传值
English,The Da Vinci Code,Chapter 1-3
Custom SOLR Search Components - 2 Dev Tricks
reading notes for solr source code
Solr: a custom Search RequestHandler
Hadoop0.20+ custom MultipleOutputFormat
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!