【问题标题】:Dynamic inject of code into iframe将代码动态注入 iframe
【发布时间】:2017-09-04 13:55:57
【问题描述】:

我正在尝试建立自己的广告网络,但我被困在同一时间点上,我如何将内容(如图像或 gif)动态注入 iframe,并保持每次相同的 src 属性( <iframe src="http://example.com/iframe.js" </iframe>) 属性?我用php尝试了一切,但没有任何效果。

【问题讨论】:

标签: javascript iframe


【解决方案1】:

要将内容添加到 iframe,您可以执行以下操作:

var doc = document.getElementById('yourIframe').contentWindow.document;
doc.open();
doc.write('Some test content');
doc.close();

【讨论】:

  • 我可以这样做吗:doc.write ('example.com/example.gif')?或者还有其他方法可以注入 gif,image ecc...?
  • 好吧,你当然会写出img标签……doc.write('<img src="/path/to/image.gif" />');
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-14
  • 2017-07-31
相关资源
最近更新 更多