移动端自定义alert窗口

来源:互联网 发布:淘宝客服标准话术 编辑:程序博客网 时间:2024/05/22 00:06

在微信端开发页面,有时候错误操作需要弹出警告框,然而警告框上面带着网址,领导觉得不美观。

于是需要有自定义alter框这需求,经过查阅资料。

有了如下代码,写了个函数。

javascript:

// 参数custom--原url代替字符//参数inenum--换行数//2017.9.25 rufffunction customAlertUrl(custom, linenum) {    window.alert = function(name) {        var hh = '\r\n';        var huangNnm = hh.repeat(linenum);        iframe = document.createElement("IFRAME");        iframe.style.display = "none";        iframe.setAttribute("src", 'data:text/plain,');        document.documentElement.appendChild(iframe);        window.frames[0].window.alert(custom + huangNnm + name);        iframe.parentNode.removeChild(iframe);    }}//默认,要引用的话再页面中添加customAlertUrl('724助理提醒您', 1);

ios:


安卓:


原创粉丝点击