javascript - How to close the already opened alert dialog box with jq or js
天蓬老师
天蓬老师 2017-05-19 10:24:57
0
3
863

How to close the open alert dialog box in jq or js

I have opened an alert through a callback function, and now I want it to be displayed for a few seconds and then automatically close. How can I do it with jq? js is also possible. If the function is hijacked, it will target all alerts on the current page. I am currently You only need to control one of the alerts, and I beg the front-end master for answers

ps: This is not the point of the question. I am afraid that someone will ask me why I did this...
In addition, I am using this for H5 web Notification. I open the reduced page through Notification's click callback. I don't know how. Writing, I had to use alert to re-maximize the page

var msg = 'test';
var n = new Notification("来自用户xxxx的新消息", {  
    icon: 'pic.png',  
    body: '消息内容:'+msg  
});  
n.onclick = function() {
    alert(1234);
    //想通过劫持函数来重新定义alert函数……但是好像是全局的……
    var ALERT_ON = true; 
    var _alert = window.alert;
    window.alert = function(msg) {
        if (ALERT_ON) {
            _alert(msg);
        }
    }
    //location.reload();
    n.close();
};
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
某草草

Alert pop-up window seems to have no way to close automatically.
You can write an alert pop-up window yourself.


I will re-edit it to get the effect the up owner wants.
Click the Notification notification to zoom in or display the current page.

Just add this line of code to the onclick of Notification.

window.focus();
洪涛

alert will interrupt the execution of JS, so this requirement cannot be realized.

过去多啦不再A梦

Because alert cannot be turned off, it can only be disabled, so it is recommended to write a pop-up box by yourself.
Use p to write a masked pop-up modal box, and then setTimeout to close it regularly.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!