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();
};
某草草2017-05-19 10:26:57
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();
PHP中文网2017-05-19 10:26:57
alert will interrupt the execution of JS, so this requirement cannot be realized.
过去多啦不再A梦2017-05-19 10:26:57
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.