Javascript:在加载的页面中获取iframe ID [英] Javascript: get iframe id within loaded page

查看:120
本文介绍了Javascript:在加载的页面中获取iframe ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有iframe的页面。每次加载页面时,iframe都会为其分配唯一的ID和名称。我可以在加载的iframe中获取iframe名称,如下所示:

I've got a page that has an iframe. Every time the page loads, iframe gets unique id and name assigned to it. I can get the iframe name within loaded iframe like so:

alert(parent.window.frames[window.name].name);

但是当我试图获得id值时:

But when i try to get the id value:

alert(parent.window.frames[window.name].id);

我得到未定义

是否可以在加载的页面中获取iframe的id属性?

Is it possible to get the id attribute of the iframe within loaded page?

http://jsfiddle.net/cqFtB/

<iframe id="lyygi8stwZSANUEh" src="http://example.com" name="zma82vRVe18xbAqW" title="Awesome Iframe">

example.com:

example.com:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Awesome Iframe</title>
</head>
<body>
    <script type="text/javascript"> 
        alert(parent.window.frames[window.name].name);
    </script>
</body>
</html>


推荐答案

尝试 window.frameElement。 iframe中的ID

这篇关于Javascript:在加载的页面中获取iframe ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆