iframe读取它的问题

时间:2010-07-05 15:06:07

标签: javascript prototypejs

原型中是否有相当于jQuery的live函数?我有一个动态加载到dom的iframe,我需要访问iframe中的元素,我不能。当iframe中的某个元素悬停时,我需要做一些事情,我怎么能用原型或原生js做呢?

2 个答案:

答案 0 :(得分:0)

假设您的iframe idiframe_id且iframe ID中的链接为iframe_link,则会显示一个原型脚本,当iframe中的链接被翻转时,该脚本将提醒“悬停” :

<script>
var $IFRAME = function (id){
    return $('iframe_id').contentWindow.document.getElementById(id);
}
function watch_iframe(){
    var x = $IFRAME('iframe_link_id');
    x.observe('mouseover', function(event) {
        alert('hover')
    });
}
window.setTimeout(watch_iframe,1000);//makes sure iframe is loaded before intiating the watch_iframe function
</script>

信用到期日:What is the way to access IFrame's element using Prototype $ method

答案 1 :(得分:0)

如果你的IFRAME在同一个域上,这是一种DOM方式:

在您的父页面中:

<iframe src="iframeContent.html"></iframe>
<script>
    function listen(elm){
        alert(elm.tagName + ' moused over');
    }
</script>

在您的iframe内容中:

<div onmouseover="top.listen(this)">
    mouse over me!
</div>