从iframe内部访问iframe名称 [英] access iframe name from inside iframe
本文介绍了从iframe内部访问iframe名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
虽然这会很简单,但我找不到答案。我需要知道如何从上述iframe中访问iframe的名称。
< iframe name =thename>
< script type =text / javascript>
alert(parent.name);
< / script>
< / iframe>
解决方案
你几乎是正确的。在框架
或 iframe
上设置名称
属性设置该框架的全局窗口
对象的名称
属性添加到该字符串。 (不是父
,它指拥有该框架的文档的窗口。) 所以除非另有其他脚本有意改变了名字,这很简单:
1.html:
2.html:
< script type =text / javascript>
alert(window.name); // tim
< / script>
I though this would be simple enough but I can't find the answer. I need to know how I can access an iframe's name from within said iframe. I was trying something like this but it's not working.
<iframe name="thename">
<script type="text/javascript">
alert(parent.name);
</script>
</iframe>
解决方案
You were nearly right. Setting the name
attribute on a frame
or iframe
sets the name
property of the frame's global window
object to that string. (Not parent
, which refers to the window of the document that owns the frame.)
So unless some other script has deliberately changed the name, it's as simple as:
1.html:
<iframe name="tim" href="2.html"></iframe>
2.html:
<script type="text/javascript">
alert(window.name); // tim
</script>
这篇关于从iframe内部访问iframe名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文