【问题标题】:How to set value to iframe in html如何在html中为iframe设置值
【发布时间】:2014-05-04 11:07:49
【问题描述】:
    Is it possible to set value as attribute to iframe in HTML? Or is there any other solution?



<iframe name="some name" src="url" value="some values"></iframe>

JS代码

我正在使用 JavaScript 访问属性,例如

parent.window.frames[window.name].name;

我的名字正确,但价值没有得到。

            if possible then how to access??

【问题讨论】:

  • 为什么需要 iframe 的 value 属性?

标签: javascript html iframe cross-domain


【解决方案1】:

window.frames[window.name] 指的是iframe 中的window 对象,而不是主页上的iframe 元素。如果您需要从 iframe 内部引用设置为 iframe 的属性,可以这样获取:

var value = window.frameElement.getAttribute('value');

如果iframe value 是自定义属性,因此它不会反映到value 属性。我建议您使用data-* attributes,而不是自定义属性。

【讨论】:

  • @Ravi Chothe 有没有 cmets?
猜你喜欢
  • 2013-05-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-25
  • 2017-03-26
  • 1970-01-01
  • 2021-08-19
  • 2014-07-17
相关资源
最近更新 更多