代码之家  ›  专栏  ›  技术社区  ›  Gandalf StormCrow

读起来有问题吗

  •  0
  • Gandalf StormCrow  · 技术社区  · 16 年前

    2 回复  |  直到 14 年前
        1
  •  0
  •   Community Mohan Dere    9 年前

    假设你的iframe id 是 iframe_id iframe_link

    <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

        2
  •  0
  •   Mic    16 年前

    如果您的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>