我怎么能重写一个匿名的JavaScript函数附加到eventlistener? [英] how can I override an anonymous javascript function attached to an eventlistener?

查看:94
本文介绍了我怎么能重写一个匿名的JavaScript函数附加到eventlistener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现一个网站有些偷偷摸摸的事情。当您将鼠标悬停在链接上时,会显示您真实的网址。当你点击它时,它使用click / mousedown事件来重写URL。

我想重写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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆