【发布时间】:2015-07-13 18:37:10
【问题描述】:
我正在运行能够操纵 CSS 和 JS 进行自定义的票务软件,我需要将视频 URL 转换为 iframe。我目前正在使用此代码:
$('#wiki-page-content').contents().each(function() {
// Skip non text nodes.
if (this.nodeType !== 3) {
return true;
}
// Grab text
var matches = this.data.match(/(?:http:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g);
if (!matches) {
return true;
}
var iframe = $('<iframe width="420" height="345" frameborder="0" allowfullscreen />', {
src: 'http://www.youtube.com/embed/' + matches[1]
});
iframe.insertAfter(this);
$(this).remove();});
现在,问题是当有人使用文本编辑器将 URL 放入 WIKI 页面时,它会在其周围包裹一个 <P></P> 标记。这会导致问题吗?我该如何克服这个问题。
【问题讨论】:
标签: javascript html css iframe youtube