Javascript - 覆盖或阻止执行 [英] Javascript - override or prevent execution

查看:57
本文介绍了Javascript - 覆盖或阻止执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个客户端项目,我必须包含它们的页眉和页脚,其中包括一些核心javascript文件。我在页面上有几个PNG,但是它们的核心JS文件编码很差,并且在尝试用包含使用AlphaImageLoader过滤器的DIVS替换包含.png文件的IMG标记之前不检查IE 7。结果是在IE 7中,所有我的.png图像都被替换为具有默认显示的块DIV标记:阻止,在我的页面中的每个单个png图像之后导致换行。

I'm working on a client project and I have to include their header and footer, which includes some core javascript files. I have a couple of PNGs on the page, but their core JS file is poorly coded and doesn't check for IE 7 before attempting to replace IMG tags that contain .png files with DIVS that use the AlphaImageLoader filter. The result is that in IE 7, all my .png images are replaced with DIV tags that have a default display: block, causing a linebreak after every single png image in my pages.

我想要做的是用更好的方法覆盖它们的功能或以某种方式阻止它们执行,但是我不能修改js文件本身,它们定义了函数并将它附加到窗口onload事件。我已经尝试在几个地方重新定义相同名称下的函数(标题,就在/ body标记之前,在$(document).ready等等...)但原始函数似乎总是执行,大概是因为原来的函数代码是与事件处理程序一起存储的函数,而不仅仅是指向函数的指针。

What I'd like to do is override their function with a better one or somehow prevent theirs from executing, but I cannot modify the js file itself, which both defines the function and attaches it to the window onload event. I've tried redefining the function under the same name in several places (header, just before the /body tag, in $(document).ready, etc...) but the original function always seems to execute, presumably because the original function code is what is stored with the event handler, and not merely a pointer to the function.

我能修复什么方式吗?有没有办法有选择地删除onload事件处理程序?

Any way I can fix? Is there a way to selectively remove onload event handlers?

推荐答案

在IE7中你可以使用detachEvent方法: -

In IE7 you can use the detachEvent method:-

window.detachEvent("load", fn)

其中fn是附加的函数,但是由于在这个混合中有jquery,它可能是一个很高的命令,可以获得附加的实际函数。最有可能附加的实际功能是匿名的。

where fn is the function that was attached, however since there is jquery in this mix it may be a tall order getting hold of the actual function that was attached. Most likely the actual function attached will be anonymous.

这篇关于Javascript - 覆盖或阻止执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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