重写Alert
var isIE = navigator.appName.indexOf("Internet Explorer") != -1;
var oldAlert = window.alert;
window.alert = function (str) {
var eSrc;
if (!isIE) {
eSrc = (document.all) ? window.event.srcElement : arguments[1];
} else {
eSrc = document.activeElement;
}
var shield = document.createElement("DIV");
shield.id = "shield";
shield.style.position = "absolute";
shield.style.left = "0px";
shield.style.top = "0px";
shield.style.width = "100%";
shield.style.height = ((document.documentElement.clientHeight > document.documentElement.scrollHeight) ? document.documentElement.clientHeight : document.documentElement.scrollHeight) + "px";
shield.style.background = "#FFF000";
shield.style.textAlign = "center";
shield.style.zIndex = "10000";
shield.style.filter = "alpha(opacity=0)";
shield.style.opacity = 0;
var alertFram = document.createElement("DIV");
alertFram.id = "alertFram";
alertFram.style.position = "absolute";
alertFram.style.left = "50%";
alertFram.style.top = "50%";
alertFram.style.marginLeft = "-225px";
alertFram.style.marginTop = -75 + document.documentElement.scrollTop + "px";
alertFram.style.width = "450px";
alertFram.style.height = "150px";
alertFram.style.background = "#ccc";
alertFram.style.textAlign = "center";
alertFram.style.lineHeight = "150px";
alertFram.style.zIndex = "10001";
strHtml = "<ul style=\"list-style:none;margin:0px;padding:0px;width:100%\">\n";
strHtml += " <li style=\"background:#DD828D;text-align:left;padding-left:20px;font-size:14px;font-weight:bold;height:25px;line-height:25px;border:1px solid #F9CADE;\">[系统提示]</li>\n";
strHtml += " <li style=\"background:#fff;text-align:center;font-size:12px;height:120px;line-height:120px;border-left:1px solid #F9CADE;border-right:1px solid #F9CADE;\">" + str + "</li>\n";
strHtml += " <li style=\"background:#FDEEF4;text-align:center;font-weight:bold;height:25px;line-height:25px; border:1px solid #F9CADE;\"><input type=\"button\" value=\"确 定\" id=\"do_OK\" onclick=\"doOk()\" /></li>\n";
strHtml += "</ul>\n";
alertFram.innerHTML = strHtml;
document.body.appendChild(alertFram);
document.body.appendChild(shield);
this.setOpacity = function (obj, opacity) {
if (opacity >= 1) opacity = opacity / 100;
try { obj.style.opacity = opacity; } catch (e) { }
try {
if (obj.filters.length > 0 && obj.filters("alpha")) {
obj.filters("alpha").opacity = opacity * 100;
} else {
obj.style.filter = "alpha(opacity=\"" + (opacity * 100) + "\")";
}
} catch (e) { }
}
var c = 0;
this.doAlpha = function () {
if (++c > 20) { clearInterval(ad); return 0; }
setOpacity(shield, c);
}
var ad = setInterval("doAlpha()", 1);
this.doOk = function () {
//alertFram.style.display = "none";
//shield.style.display = "none";
document.body.removeChild(alertFram);
document.body.removeChild(shield);
eSrc.focus();
document.body.onselectstart = function () { return true; }
document.body.oncontextmenu = function () { return true; }
}
document.getElementById("do_OK").focus();
eSrc.blur();
document.body.onselectstart = function () { return false; }
document.body.oncontextmenu = function () { return false; }
}
效果如下:
样式还可自己再改
}
重写Alert的更多相关文章
- JS重写alert,保证弹窗错误的友好性
// ------------------------------------------------------------- // 重写alert,保证弹窗错误的友好性 var j_oldAler ...
- 重写alert方法,去掉地址显示
//重写alert方法,去掉地址显示window.alert = function(name){ var iframe = document.createElement("IFRAME&qu ...
- [Winform]Cefsharp重写alert与confirm弹窗
摘要 在使用winform内嵌cefsharp浏览本地页面的时候,如果出现alert弹窗,会在标题栏显示页面所在目录.所以想起来重写alert的样式,通过winform的MessageBox进行提示. ...
- 重写Alert和confirm方法去除地址显示
//重写alert方法,去掉地址显示window.alert = function(name){var iframe = document.createElement("IFRAME&quo ...
- js重写alert()弹窗
//重写alertwindow.alert = function(str){ var alertFram = document.getElementById('alertFram'); var shi ...
- Cef 重写alert与confirm弹窗
在使用form内嵌cef浏览本地页面的时候,如果出现alert弹窗,会在标题栏显示页面所在目录.所以想起来重写alert的样式,通过MessageBox进行提示,或者自己写一个弹窗. 以下代码基于 3 ...
- 重写alert方法完成类似gmail的友好提示
当在网页中调用aelrt()方法的时候,系统会自动显示友好的提示方式 . 下面是css样式控制代码: /*----------------------------------------------- ...
- 自定义alert弹框,title不显示域名(重写alert)
问题: 系统默认的alert弹框的title会默认显示网页域名 解决办法: (修改弹框样式) (function() { window.alert = function(name) { $(" ...
- js 重写alert 兼容iphone使得alert 不带src
<script> window.alert = function(name){ var iframe = document.createElement("IFRAME" ...
- JS 重写alert,使之能输出多个参数
windows._alert = windows.alert; windows.alert = function(){ _alert = (Array.prototype.slice(argument ...
随机推荐
- Elasticsearch 中文分词器IK
1.安装说明 https://github.com/medcl/elasticsearch-analysis-ik 2.release版本 https://github.com/medcl/elast ...
- BZOJ4557:[JLOI2016/SHOI2016]侦察守卫——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4557 小R和B神正在玩一款游戏.这款游戏的地图由N个点和N-1条无向边组成,每条无向边连接两个点, ...
- hdu6184 Counting Stars 【三元环计数】
题目链接 hdu6184 题解 题意是让我们找出所有的这样的图形: 我们只需要求出每条边分别在多少个三元环中,记为\(x\),再然后以该点为中心的图形数就是\({x \choose 2}\) 所以我们 ...
- 洛谷 P1505 [国家集训队]旅游 解题报告
P1505 [国家集训队]旅游 题目描述 \(\tt{Ray}\) 乐忠于旅游,这次他来到了\(T\)城.\(T\)城是一个水上城市,一共有 \(N\) 个景点,有些景点之间会用一座桥连接.为了方便游 ...
- SP7586 NUMOFPAL - Number of Palindromes 解题报告
SP7586 NUMOFPAL - Number of Palindromes 题意翻译 求一个串中包含几个回文串 输入输出格式 输入格式: The string S. 输出格式: The value ...
- UVA.11464 Even Parity (思维题 开关问题)
UVA.11464 Even Parity (思维题 开关问题) 题目大意 给出一个n*n的01方格,现在要求将其中的一些0转换为1,使得每个方格的上下左右格子的数字和为偶数(如果存在的话),求使得最 ...
- atom的快捷键,你hold住吗?
命令面板:Ctrl+Shift+P设置窗口:Ctrl+,另存为: Ctrl+Shift+S添加文件:Ctrl+O添加文件夹:Ctrl+Alt+O工程内查找 :Cmd+Shift+F a,m,delet ...
- lamp 源码安装
#!/bin/bash #description:mysql-.tar apache2.4.23 php5.6.27 function check_ok(){ ] then echo "-- ...
- @RequestParam 注解的使用
@RequestParam 注解的使用 前言 在SpringMvc后台进行获取数据,一般是两种. 1.request.getParameter(“参数名”) 2.用@RequestParam注解获取 ...
- Divide by Three CodeForces - 792C
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You ...