如何“自动关闭”警报框 [英] How to "auto close" Alert boxes

查看:167
本文介绍了如何“自动关闭”警报框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个由不再存在的公司制作的控件。
由于页面加载的一些奇怪的原因,它现在开始向页面呈现这样的内容:

We have a control that was made by a company that no longer exists. For some odd reason on page load it has now started rendering something like this to the page:

<script type="text/javascript">
 alert('Your license has expired!')
</script>

由于公司不再存在,我们无法获得支持,控制也非常复杂,运行一些无法快速替换的遗留代码,因此简单地重写页面也不是一个选项(还)。

Since the company no longer exists we can't get support and the control is also very complex and is running in some legacy code that can't be quickly replaced so simply rewriting the page is also not an option (yet).

我暂时需要做什么是通过某些脚本在页面呈现或自动关闭之前从页面中删除对话框...

What I need to do for the time being is to have the dialog either be removed from the page before it renders or auto closed by some script ...

任何想法?

推荐答案

你无法关闭一个警告框,只是你可以劫持window.alert

You can not close an alert box, just you can hijack window.alert

window._alert = window.alert;
window.alert = function () {    
};

代码必须出现在第三方库的代码之前。这意味着,如果您想使用警报,则必须更改代码。

The code would have to appear before the third party library's code. What this means is, if you want to use an alert, you would have to change your code.

一种方法是调用具有引用的方法

One way would to call the method that has the reference

window._alert("hi");

其他方式是重载新功能

window._alert = window.alert;
window.alert = function (msg, showItNow) {    
    if (showItNow) {
        window._alert(msg);
    }
};
window.alert("BOOOO!");  //I will not show up
window.alert("hi", true); //I will show up

这篇关于如何“自动关闭”警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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