前端JavaScript的技术技巧交流~

隐藏浏览器默认的alert,confirm的网址方法记录

2018-12-13  本文已影响0人  chouchou723

confirm方法如下

window.confirm = function(name) {
   const iframe = document.createElement("IFRAME");
   frame.style.display = "none";
   iframe.setAttribute("src", 'data:text/plain,');
   document.documentElement.appendChild(iframe);
    const result = window.frames[0].window.confirm(name);
    iframe.parentNode.removeChild(iframe);
     return result;
    }
let r = confirm('是否要关闭当前页面')
          if (r == true) {
            this.$wechat.closeWindow();
          } else {}

alert方法如下:

window.alert = function (name) {
      var iframe = document.createElement("IFRAME");
      iframe.style.display = "none";
      iframe.setAttribute("src", 'data:text/plain,');
      document.documentElement.appendChild(iframe);
      window.frames[0].window.alert(name);
      iframe.parentNode.removeChild(iframe);
    }
window.alert('页面重新加载')
上一篇 下一篇

猜你喜欢

热点阅读