自定义alert弹框,title不显示域名

问题: 系统默认的alert弹框的title会默认显示网页域名

解决办法:

(修改弹框样式)

(function() {
window.alert = function(name) {
$(".tip").css("display", "block")
$(".tip .content").html(name)
}
})()

调用:alert(name)

在页面中添加弹框元素,自定义其样式,默认隐藏

:alert()方法重写,不能传多余参数

(仅去掉网址)

(function(){
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);
}
})();
alert('试一试');

也可以试试这个:(推荐使用)

Window.prototype.alert = function(){
  //创建一个大盒子
    var box = document.createElement("div");
  //创建一个关闭按钮
    var button = document.createElement("button");
  //定义一个对象保存样式
    var boxName = {
        width:"500px",
        height:"180px",
        backgroundColor:"#f8f8f8",
        border:"1px solid #ccc",
        position:"absolute",
        top:"50%",
        left:"50%",
        margin:"-90px 0 0 -250px",
        zIndex:"999",
        textAlign:"center",
        lineHeight:"180px"
    }
  //给元素添加元素
    for(var k in boxName){
        box.style[k] = boxName[k];
    }
  //把创建的元素添加到body中
    document.body.appendChild(box);
  //把alert传入的内容添加到box中
    if(arguments[0]){
        box.innerHTML = arguments[0];
    }
    button.innerHTML = "关闭";
   //定义按钮样式
    var btnName = {
        border:"1px solid #ccc",
        backgroundColor:"#fff",
        width:"70px",
        height:"30px",
        textAlign:"center",
        lineHeight:"30px",
        outline:"none",
        position:"absolute",
        bottom:"10px",
        right:"20px",
    }
    for(var j in btnName){
        button.style[j] = btnName[j];
    }
  //把按钮添加到box中
    box.appendChild(button);
  //给按钮添加单击事件
    button.addEventListener("click",function(){
        box.style.display = "none";
    })
}


alert("我的好朋友JavaScript```")

转载地址:

https://www.cnblogs.com/lvshuya/p/6549525.html

https://www.cnblogs.com/pssp/p/5246133.html

推荐:重新定义alert样式

https://blog.csdn.net/u011511210/article/details/54406226

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值