我怎么能重写一个匿名的JavaScript函数附加到eventlistener? [英] how can I override an anonymous javascript function attached to an eventlistener?
问题描述
我想重写firefox中的这个行为,所以我启动了firebug来查看它的功能。在点击鼠标时,它执行一个叫做window.tgs的函数。很简单,我想。我可以覆盖这个功能。
我的第一个尝试是通过getELementsByTagName()获取元素,然后元素.removeEventListener() click,window.tgs,false);
令我吃惊的是,这没有做任何事情。
我试着重新定义window.tgs
window.tgs = function(){return true; };
也没有做任何事情。
我不是JS专家。感谢您的见解
感谢
Sid
没有真正弄清楚如何解决这个问题,所以我的方法解决了这个问题。我添加了另一个eventlistener,它颠倒了所讨论的功能的一切。糟糕的黑客,但它的作品
I found that a website does somewhat sneaky things. When you hover over a link, it shows you the real URL. WHen you click on it, it uses the click/mousedown event to rewrite the URL.
I want to override that behaviour in firefox, So I fired up firebug to see what it does. On a mouse click, it executes a function called window.tgs. Easy, I thought. I can override this function.
My first attempt was to do get the element via getELementsByTagName(), and then
element.removeEventListener("click",window.tgs, false);
To my surprise, this did nothing.
I tried redefining window.tgs window.tgs = function() { return true; };
that did not do anything either.
I am not a JS expert. Your insights appreciated
thanks Sid
I did not really figure out how to fix this, so worked my way around it. I added another eventlistener which reversed everything that the function in question did. Lousy hack, but it works
这篇关于我怎么能重写一个匿名的JavaScript函数附加到eventlistener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!