如何“自动关闭”警报框

编程入门 行业动态 更新时间:2024-10-28 14:25:50
本文介绍了如何“自动关闭”警报框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

如何“自动关闭”警报框

本文发布于:2023-11-27 16:46:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   自动关闭

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!