动态 vimeo 嵌入选项

发布于 2025-01-07 21:09:58 字数 694 浏览 3 评论 0原文

我正在尝试添加带有选项(颜色等)的 Vimeo 嵌入。然而,如果 iframe 是使用 jQuery 或 DOM 创建的,Vimeo 似乎无法识别这些选项:

var fail = $('<iframe>', {
    src: 'http://player.vimeo.com/video/36825140?title=0&amp;byline=0&amp;portrait=0&amp;color=a4a9ab'
});

但是,如果我使用innerHTML,它就可以工作(它也可以使用纯 HTML 工作)。

var ok = $('<div>').html('<iframe src="http://player.vimeo.com/video/36825140?title=0&amp;byline=0&amp;portrait=0&amp;color=a4a9ab"></iframe>');

测试小提琴: http://jsfiddle.net/nhkr5/

我真的很想使用 DOM 工具来完成该任务,这样我就可以引用 iframe 元素并摆脱额外的包装器。

还有另一种“正确”的方法吗?

I’m trying to add Vimeo embeds with options (colors, etc). However, it seems that Vimeo doesn’t recognize the options if the iframe is created using jQuery or DOM:

var fail = $('<iframe>', {
    src: 'http://player.vimeo.com/video/36825140?title=0&byline=0&portrait=0&color=a4a9ab'
});

But, if I use innerHTML, it works (it also works using plain HTML).

var ok = $('<div>').html('<iframe src="http://player.vimeo.com/video/36825140?title=0&byline=0&portrait=0&color=a4a9ab"></iframe>');

Test fiddle: http://jsfiddle.net/nhkr5/

I would really like to use DOM tools for the task, so I can reference the iframe element and get rid of the extra wrapper.

Is there another "correct" way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与之呼应 2025-01-14 21:09:58

如果您检查动态创建的 iframe,您会发现 & 实体未解析,因此 src 中没有 &,但字面意思 &

http://jsfiddle.net/ nhkr5/1/

If you inspect the dynamically created iframe, you will discover that the & entities are not resolved, so you don't have & in the src, but literal &

http://jsfiddle.net/nhkr5/1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文