javascript - 将 iframe 的内容设置为 polymer 元素

标签 javascript jquery html iframe polymer

我正在尝试使用以下代码将 iframe 的内容动态设置为 polymer 元素:

$(this.$.frame).contents().find('html').html("<custom-element></custom-element>");

不幸的是,这不起作用。 (iframe 只是空的)

有趣的是,当您不使用 polymer 元素时,上面的代码仍然有效。

例如

$(this.$.frame).contents().find('html').html("This works");

完美运行。

感谢您的帮助。

最佳答案

我怀疑问题出在 iframe 运行时有它自己的文档上下文和它自己的 javascript 上下文。这意味着您在文档中注册的自定义元素对于 iframe 是未知的。

尝试:

var source = '<script src='path/to/platform/platform.js'></script>';
source += '<link rel='import' href='path/to/custom-element/custom-element.html'>';
source += '<custom-element></custom-element>';
$(this.$.frame).contents().find('html').html(source);

关于javascript - 将 iframe 的内容设置为 polymer 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25487247/

相关文章:

javascript - Bootstrap datetimepicker 小部件中的语言

javascript - 为什么 jQuery 轮播不能与 iframe 一起使用?

javascript - CacheStorage.open() 在 Chrome 中返回未定义

jquery - 在滚动之前,使用 jQuery 更改类不起作用

javascript - 如何使 setTimeout 表现得像等待

html - 适合对象 : cover with percentages

html - 页面不会在任何浏览器中滚动——我使用的是过时的 CSS 吗?

javascript - 单击后隐藏菜单(淡出)

javascript - 将回调函数传递给 jQuery AJAX 成功函数

php - 如何动态生成带有 alpha 渐变的图像?