简体   繁体   English

将iframe的内容设置为聚合物元素

[英]Set the content of an iframe to a polymer element

I am trying to dynamically set the content of an iframe to a polymer element using the following code: 我正在尝试使用以下代码将iframe的内容动态设置为聚合物元素:

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

Unfortunately, this doesn't work. 不幸的是,这不起作用。 (The iframe is just empty) (iframe只是空的)

The interesting thing is that the code above works when you don't use a polymer element. 有趣的是,当您不使用聚合物元素时,上面的代码将起作用。

eg 例如

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

works perfectly. 完美地工作。

Thanks for your help. 谢谢你的帮助。

I suspect that the issue is that the iframe is running with its own document context, and its own javascript context. 我怀疑问题出在iframe使用自己的文档上下文和自己的javascript上下文运行。 That means that the custom elements you've registered in your document are unknown to the iframe. 这意味着iframe不知道您在文档中注册的自定义元素。

Try: 尝试:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM