0

IFRAME内にIFRAMEがあり、getMousePositionメソッドがiframe内の現在のマウス位置を取得できません。最初のIframeで機能しますが、親ドキュメントの関数からgetMousePositionを呼び出すと、フォールバック値600と350が返されます。参考:生成されたIFrameのコンテンツを制御することはできませんが、そうではありません。クロスドメインアクセス。IFRAMESと親ドキュメントの両方が同じサーバーでホストされています。私はInternetExplorer8用にプログラミングしているだけなので、ブラウザーの互換性は問題ではありません。

  function getMousePosition(){
  if(!inframe)
      $(document).mousemove(function(e){
           mouseX = e.pageX 
           mouseY = e.pageY 
      });
  else
  {
    mouseX = 600;
    mouseY = 350;
  }

  //This is where I get the Iframe Document (I then parse through the document, picking up the specific links and storing them in the array verifiedlinks)
  var src = window.frames[iframeindex].document.getElementsByTagName("a");
  // This is where I call my function which uses the values returned by getMousePosition (verifiedlinks is an array of links inside the iframe):

    verifiedlinks[i].onmouseover = function() 
    {
        showPeopleDetails(this.getAttribute('username'));
    }
  // This should display User Details at the current Mousecoordinates
function showPeopleDetails(UserId){
var vpd = document.getElementById("PeopleDetails");
    if ( vpd != null ) {
        getMousePosition();
        vpd.style.left=mouseX+10; //mouseX and mouseY are defined globally
        vpd.style.top=mouseY+10;
        vpd.style.display="block";
    }
}

私はこの質問を読みました:解決された質問ですが、答えは私の問題を解決しませんでした。私はこの質問を見つけましたが、答えのどれも私のために働いていないようです。私の新しい編集されたコード:

function showPeopleDetails(UserId, x, y){
var vpd = document.getElementById("PeopleDetails");
try
{
    if ( vpd != null ) {
        //getMousePosition();
        //alert("MouseX: " +mouseX+" MouseY: "+mouseY);
        //vpd.style.left=mouseX+10;
        //vpd.style.top=mouseY+10;
        vpd.style.left = x +10 - window.frames[2].document.body.scrollLeft;
        vpd.style.top = y +10 - window.frames[2].document.body.scrollTop;
     }
}
4

1 に答える 1

1

親ウィンドウからgetMousePositionを呼び出すと、ドキュメントは親ウィンドウのドキュメントを指します。このメソッドは、iframeのコンテキストで呼び出す必要があります。また、インフレームはどこで定義されており、イベントでその値を更新しますか?

jqueryを使用して、マウスオーバーイベントをリンクにアタッチできます。これを使用すると、ドキュメントに関連するリンクのマウスx/y座標を提供するイベントオブジェクトを取得します。お役に立てば幸いです。

$(verifiedlinks[i]).mouseover(function(e){
        showPeopleDetails($(this).attr('username'), e.pageX, e.pageY);
}

function showPeopleDetailsNow(UserId, x, y){
var vpd = document.getElementById("PeopleDetails");
    if ( vpd != null ) {
        getMousePosition();
        //vpd.style.left=mouseX+10; //mouseX and mouseY are defined globally
        //vpd.style.top=mouseY+10;
        vpd.style.left= x +10 + $(document).scrollTop(); //mouseX and mouseY are defined globally
        vpd.style.top= y +10;
        vpd.style.display="block";
    }
}
于 2011-08-01T14:13:13.353 に答える