当(触发)控制台显示错误时显示或隐藏Div(Show or Hide a Div When (Triggered By) Console Displays An Error)

系统教程 行业动态 更新时间:2024-06-14 16:59:47
当(触发)控制台显示错误时显示或隐藏Div(Show or Hide a Div When (Triggered By) Console Displays An Error)

这里的问题是我正在使用一个具有本机错误的javascript库,当按下某组按钮太多次(超过特定限制)时,该错误会不断弹出。 然后需要刷新页面(现在直到本机问题得到解决)。

我已将此警报添加到我的html中,基本上我希望它在控制台报告错误时弹出。 (我正在使用Chrome)

<div class="alert alert-danger" role="alert" style="display:none;">Please Refresh Page</div>

要做到这一点,我基本上会像这样使用jquery:

$('.alert').fadeIn()

但是我不确定如何触发那个简单的jquery调用。 我怎样才能在控制台上监听,当控制台报告错误时,调用该jquery函数使警报横幅可见?

我无法找到我的问题的明确答案,希望StackOverflow社区有它! 提前致谢。

The issue here is that I'm using a javascript library that has a native error that keeps popping up when a certain group of buttons are pressed too many times (over a specific limit). The page then needs to be refreshed (For now until the native issue is worked out).

I have added this alert to my html, essentially I want it to pop up the moment when the console reports an error. (I am using Chrome)

<div class="alert alert-danger" role="alert" style="display:none;">Please Refresh Page</div>

To do this I would essentially use jquery like so:

$('.alert').fadeIn()

However I am unsure as to how I would trigger that simple jquery call. How could I listen in on the console, and when the console reports an error, call that jquery function to make that alert banner visible?

I have not been able to find a clear answer to my question, hopefully the StackOverflow Community has it! Thanks in advance.

最满意答案

使用这个链接我通过这样做得到了你想要的效果在这个codepen中 :

window.onerror = function(error, url, line) { $('.alert').fadeIn(); };

Using this link I got you're desired effects in this codepen by doing this:

window.onerror = function(error, url, line) { $('.alert').fadeIn(); };

更多推荐

本文发布于:2023-04-17 09:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/6211f2b16349381fd82a2b55b73c14b8.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   错误   Show   Div   Hide

发布评论

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

>www.elefans.com

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