在Vimperator插件中模拟鼠标悬停 [英] Simulate Mouse Over in Vimperator plugin
问题描述
我正在尝试编写一个Vimperator插件,允许使用提示模式在下拉菜单上模拟鼠标。我有提示模式工作,可以正确选择附加鼠标悬停事件的元素。问题是我的模拟鼠标功能不起作用。这就是我目前所拥有的:
I'm attempting to write a Vimperator plugin to allow use of hints mode to simulate mouse over on drop down menus. I have the hints mode working and can correctly choose elements that have mouseover events attached. The problem is my function to simulate the mouse over is not working. This is what I currently have:
function SimulateMouseOver(elem)
{
var evt = elem.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('mouseover',true,true,
elem.ownerDocument.defaultView,0,0,0,0,0,
false,false,false,false,0,null);
var canceled = !elem.dispatchEvent(evt);
if(canceled)
alert('Event Cancelled');
}
以上代码适用于某些页面,但不适用于其他页面。例如,它不适用于AccuWeather。任何想法如何模拟鼠标都适用于大多数页面?
The above code works for some pages but not for others. For example it doesn't work on AccuWeather. Any ideas how to simulate a mouse over that will work for most pages?
推荐答案
这里有一些代码来开始创建事件,更简单,适用于更多浏览器(如果您不需要指定精确的鼠标坐标)
here's some code to start with to create the event, simpler and works for more browsers (if you don't need to specify exact mouse coordinates)
if( document.createEvent ) {
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( 'mouseover', true, false );
elem.dispatchEvent(evObj);
} else if( document.createEventObject ) {
elem.fireEvent('onmouseover');
}
希望有帮助
这篇关于在Vimperator插件中模拟鼠标悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!