代码之家  ›  专栏  ›  技术社区  ›  Talha Bin Shakir

iframe鼠标移动时调用函数

  •  0
  • Talha Bin Shakir  · 技术社区  · 16 年前

    我有一个函数需要调用iframe mousemove()。但我没在尸体标签上找到什么 我们有 <body mousemove="Function()"> 我们有像这样的iFrame吗??

    2 回复  |  直到 16 年前
        1
  •  1
  •   nlogax    16 年前

    这个 iframe 包含自己的 document 自己的 body 元素等。 尝试如下操作:

    var frame = document.getElementById("yourIframeId");
    // IE is special
    var frameDoc = frame.contentDocument || frame.contentWindow.document;
    var frameBody = frameDoc.getElementsByTagName("body")[0];
    
    var testingOneTwo = function() {
        console.log("Hello, is this thing on?");
    };
    frameBody.onmouseover = testingOneTwo;
    
        2
  •  0
  •   priyanka.sarkar    16 年前

    你是说 onMouseOver onFocus ?

    例如

    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>  
      <script language="javascript">
      <!--
    function SayHello()
    {
     alert("Hi from IFrame");
    }
    
      //-->
      </script>
     </HEAD>
    
     <BODY>
     <iframe id="myiFrame" onMouseOver="SayHello()"/>
    <iframe id="myiFrame" onFocus="SayHello()"/>
     </BODY>
    </HTML>