如何在html中为iframe设置值

时间:2014-03-26 07:36:58

标签: javascript html iframe cross-domain

    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??

1 个答案:

答案 0 :(得分:0)

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

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

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