我在 IFRAME 中有一个 IFRAME,而我的 getMousePosition 方法无法检索 iframe 中的当前鼠标位置。它在第一个 Iframe 中工作,但是当我从父文档中的函数调用 getMousePosition 时,它返回后备值 600 和 350。仅供参考:我无法控制生成 IFrame 的内容,但它不是跨域访问。IFRAMES 和父文档都托管在同一台服务器上。我只是为 Internet Explorer 8 编程。所以浏览器兼容性不是问题。
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;
}
}