Personalized web page pop-up window
看到论坛上有人模仿alert,自己也写了一个。
本来想模仿winapi里的MessageBox
但可惜js 不支持,阻塞模式。
返回值只能用异步了。
支持FF、ie、opera。
DOCTYPE 可以申明,也可以不申明。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>MessageBox演示</title> <script language="javascript"> /******************************************************************************************* * http://2lin.net * Email:caoailin@gmail.com * QQ:38062022 * Creation date: 2006-11-27 * 下面的内容可以拷贝到一个JS文件里面 *********************************************************************************************/ // 控制按钮常量 var MB_OK = 0; var MB_CANCEL = 1; var MB_OKCANCEL = 2; var MB_YES = 3; var MB_NO = 4; var MB_YESNO = 5; var MB_YESNOCANCEL = 6; // 控制按钮文本 var MB_OK_TEXT = "确定"; var MB_CANCEL_TEXT = "取消"; var MB_YES_TEXT = " 是 "; var MB_NO_TEXT = " 否 "; //提示图标 var MB_ICON = "http://www.cnn6.net??/files/080516/1_011452.gif"; //委托方法 var MB_OK_METHOD = null; var MB_CANCEL_METHOD = null; var MB_YES_METHOD = null; var MB_NO_METHOD = null; var MB_BACKCALL = null; var MB_STR = '<style type="text/css"><!--' + 'body{margin:0px;}' + '.msgbox_title{background-color: #B1CDF3;height:25px;position:relative;font-size:14px;line-height:25px;padding-left:10px;border-bottom:1px solid #000;}' + '.msgbox_control{text-align:center;clear:both;height:28px;}' + '.msgbox_button{background-color: #B1CDF3;border:1px solid #003366;font-size:12px;line-height:20px;height:21px;}' + '.msgbox_content{padding:10px;float:left;line-height: 20px;}' + '.msgbox_icon{width: 50px;height: 50px;float: left;text-align: center;line-height:50px;padding-top:10px;}' + '.msgbox_mask{position:absolute;left:0px;top:0px;z-index:99999;background-color:#333333;width:100%;height:100%;}' + '.msgbox{background-color: #EFFAFE;position: absolute;height:auto;font-size:12px;top:50%;left:50%;border:1px solid #999999;}' + '--></style>' + '<div id="msgBoxMask" class="msgbox_mask" style="filter: alpha(opacity=0);display:none;"></div>' + '<div class="msgbox" style="display:none; z-index:100000;" id="msgBox">' + '<div class="msgbox_title" id="msgBoxTitle"></div>' + '<div class="msgbox_icon" id="msgBoxIcon"></div>' + '<div class="msgbox_content" id="msgBoxContent"></div>' + '<div class="msgbox_control" id="msgBoxControl"></div></div>'; var Timer = null; document.write(MB_STR); var icon = new Image(); icon.src = MB_ICON; /* 提示对话框 * 参数 1 : 提示内容 * 参数 2 : 提示标题 * 参数 3 : 图标路径 * 参数 4 : 按钮类型 */ function MessageBox(){ var _content = arguments[0] || "这是一个对话框!"; var _title = arguments[1] || "提示"; var _icon = arguments[2] || MB_ICON; var _button = arguments[3] || MB_OK; MB_BACKCALL = arguments[4]; var _iconStr = '<img src="{0}">'; var _btnStr = '<input name="{0}" id="{0}" type="button" class="msgbox_button" value="{1}" onclick="MBMethod(this)" />'; switch(_button) { case MB_CANCEL : _btnStr = _btnStr.toFormatString("msgBoxBtnCancel", MB_CANCEL_TEXT); break; case MB_YES : _btnStr = _btnStr.toFormatString("msgBoxBtnYes", MB_YES_TEXT); break; case MB_NO : _btnStr = _btnStr.toFormatString("msgBoxBtnNo", MB_NO_TEXT); break; case MB_OKCANCEL : _btnStr = _btnStr.toFormatString("msgBoxBtnOk", MB_OK_TEXT) + " " + _btnStr.toFormatString("msgBoxBtnCancel", MB_CANCEL_TEXT); break; case MB_YESNO : _btnStr = _btnStr.toFormatString("msgBoxBtnYes", MB_YES_TEXT) + " " + _btnStr.toFormatString("msgBoxBtnNo", MB_NO_TEXT); break; case MB_YESNOCANCEL : _btnStr = _btnStr.toFormatString("msgBoxBtnYes", MB_YES_TEXT) + " " + _btnStr.toFormatString("msgBoxBtnNo", MB_NO_TEXT) + " " + _btnStr.toFormatString("msgBoxBtnCancel", MB_CANCEL_TEXT); break; default : _btnStr = _btnStr.toFormatString("msgBoxBtnOk", MB_OK_TEXT); break; } //解决 FF 下会复位 ScrollTop = GetBrowserDocument().scrollTop; ScrollLeft = GetBrowserDocument().scrollLeft; GetBrowserDocument().style.overflow = "hidden"; GetBrowserDocument().scrollTop = ScrollTop; GetBrowserDocument().scrollLeft = ScrollLeft; $("msgBoxTitle").innerHTML = _title; $("msgBoxIcon").innerHTML = _iconStr.toFormatString(_icon); $("msgBoxContent").innerHTML = _content; $("msgBoxControl").innerHTML = _btnStr; OpacityValue = 0; $("msgBox").style.display = ""; try{$("msgBoxMask").filters("alpha").opacity = 0;}catch(e){}; $("msgBoxMask").style.opacity = 0; $("msgBoxMask").style.display = ""; $("msgBoxMask").style.height = GetBrowserDocument().scrollHeight + "px"; $("msgBoxMask").style.width = GetBrowserDocument().scrollWidth + "px"; Timer = setInterval("DoAlpha()",1); //设置位置 $("msgBox").style.width = "100%"; $("msgBox").style.width = ($("msgBoxIcon").offsetWidth + $("msgBoxContent").offsetWidth + 2) + "px"; $("msgBox").style.marginTop = (-$("msgBox").offsetHeight/2 + GetBrowserDocument().scrollTop) + "px"; $("msgBox").style.marginLeft = (-$("msgBox").offsetWidth/2 + GetBrowserDocument().scrollLeft) + "px"; if(_button == MB_OK || _button == MB_OKCANCEL){ $("msgBoxBtnOk").focus(); }else if(_button == MB_YES || _button == MB_YESNO || _button == MB_YESNOCANCEL){ $("msgBoxBtnYes").focus(); } } var OpacityValue = 0; var ScrollTop = 0; var ScrollLeft = 0; function GetBrowserDocument() { var _dcw = document.documentElement.clientHeight; var _dow = document.documentElement.offsetHeight; var _bcw = document.body.clientHeight; var _bow = document.body.offsetHeight; if(_dcw == 0) return document.body; if(_dcw == _dow) return document.documentElement; if(_bcw == _bow && _dcw != 0) return document.documentElement; else return document.body; } function SetOpacity(obj,opacity){ if(opacity >=1 ) opacity = opacity / 100; try{obj.style.opacity = opacity; }catch(e){} try{ if(obj.filters){ obj.filters("alpha").opacity = opacity * 100; } }catch(e){} } function DoAlpha(){ if (OpacityValue > 20){clearInterval(Timer);return 0;} OpacityValue += 5; SetOpacity($("msgBoxMask"),OpacityValue); } function MBMethod(obj) { switch(obj.id) { case "msgBoxBtnOk" : if(MB_BACKCALL) {MB_BACKCALL(MB_OK);} else {if(MB_OK_METHOD) MB_OK_METHOD();} break; case "msgBoxBtnCancel" : if(MB_BACKCALL) {MB_BACKCALL(MB_CANCEL);} else {if(MB_CANCEL_METHOD) MB_CANCEL_METHOD();} break; case "msgBoxBtnYes" : if(MB_BACKCALL) {MB_BACKCALL(MB_YES);} else {if(MB_YES_METHOD) MB_YES_METHOD();} break; case "msgBoxBtnNo" : if(MB_BACKCALL) {MB_BACKCALL(MB_NO);} else {if(MB_NO_METHOD) MB_NO_METHOD();} break; } MB_OK_METHOD = null; MB_CANCEL_METHOD = null; MB_YES_METHOD = null; MB_NO_METHOD = null; MB_BACKCALL = null; MB_OK_TEXT = "确定"; MB_CANCEL_TEXT = "取消"; MB_YES_TEXT = " 是 "; MB_NO_TEXT = " 否 "; $("msgBox").style.display = "none"; $("msgBoxMask").style.display = "none"; GetBrowserDocument().style.overflow = ""; GetBrowserDocument().scrollTop = ScrollTop; GetBrowserDocument().scrollLeft = ScrollLeft; } String.prototype.toFormatString = function(){ var _str = this; for(var i = 0; i < arguments.length; i++){ _str = eval("_str.replace(/\\{"+ i +"\\}/ig,'" + arguments[i] + "')"); } return _str; } function $(obj){ return document.getElementById(obj); } /////////////////////////////////////////////////////////////////////////////////////// </script> <script language="javascript"> function test() { var _msg = "<font color=red><b>演示:</b></font><br/>普通对话框!"; MessageBox(_msg); } function test1() { MB_OK_METHOD = function(){alert('你按了OK');} MB_YES_METHOD = function(){alert('你按了YES');} MB_NO_METHOD = function(){alert('你按了NO');} MB_CANCEL_METHOD = function(){alert('你按了CANCEL');} var _msg = "<font color=red><b>演示:</b></font><br/>调用对话框。是、否、取消"; MessageBox(_msg,"演示",null,MB_YESNOCANCEL); } function test2() { var _msg = "<font color=red><b>演示:</b></font><br/>调用对话框。是、否、取消"; MessageBox(_msg,"演示",MB_ICON,MB_YESNOCANCEL,callback); } function test4() { var _msg = "<font color=red><b>演示:</b></font><br/>调用对话框。确定、取消"; MessageBox(_msg,"演示",MB_ICON,MB_OKCANCEL,callback); } function callback(value) { switch(value) { case MB_OK : alert('你按了OK'); break; case MB_YES : alert('你按了YES'); break; case MB_NO : alert('你按了NO'); break; case MB_CANCEL : alert('你按了CANCEL'); break; } } function test3() { MB_YES_TEXT = "演示一"; MB_NO_TEXT = "演示二"; MB_CANCEL_TEXT = "演示三"; var _msg = "<font color=red><b>演示:</b></font><br/>这是自定义的对话框<br/> <font color=green>MB_YES_TEXT MB_NO_TEXT MB_CANCEL_TEXT MB_OK_TEXT</font>"; MessageBox(_msg,"演示",MB_ICON,MB_YESNOCANCEL,callback); } </script> </head> <body> <table width="1500" height="1000" border="1" bordercolor="#000000"> <tr> <td> </td> <td align="center"><a href="javascript:test()">普通演示</a></td> <td> </td> </tr> <tr> <td> </td> <td align="center"><a href="javascript:test1()">回调演示一</a> <label></label></td> <td> </td> </tr> <tr> <td> </td> <td align="center"><a href="javascript:test2()">回调演示二 </a></td> <td> </td> </tr> <tr> <td> </td> <td align="center"><a href="javascript:test4()">回调演示三</a><a href="javascript:test3()"></a></td> <td> </td> </tr> <tr> <td> </td> <td align="center"><a href="javascript:test3()">自定义演示 </a></td> <td> </td> </tr> </table> </body> </html>
The above is the detailed content of Personalized web page pop-up window. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to send web pages to the desktop as a shortcut in Edge browser? Many of our users want to display frequently used web pages on the desktop as shortcuts for the convenience of directly opening access pages, but they don’t know how to do it. In response to this problem, the editor of this issue will share the solution with the majority of users. , let’s take a look at the content shared in today’s software tutorial. The shortcut method of sending web pages to the desktop in Edge browser: 1. Open the software and click the "..." button on the page. 2. Select "Install this site as an application" in "Application" from the drop-down menu option. 3. Finally, click it in the pop-up window

To set the automatic refresh of a web page, you can use the HTML "meta" tag, the JavaScript "setTimeout" function, the "setInterval" function or the HTTP "Refresh" header. Detailed introduction: 1. Use the "meta" tag of HTML. In the "<head>" tag of the HTML document, you can use the "meta" tag to set the automatic refresh of the web page; 2. The "setTimeout" function of JavaScript, etc.

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

Solutions to inaccessible web pages include checking the network connection, clearing the browser cache, checking the web page address, trying to use other browsers, checking the server status, checking the domain name resolution, checking the firewall and security settings and contacting the website administrator. Detailed introduction: 1. Check the network connection to ensure that the network connection is normal. You can try to open other web pages or use other devices to access to determine whether it is a network connection problem. If other web pages can be accessed normally, it may be a problem with the web page; 2. Clear the browser cache. The browser cache may cause the web page to fail to load, etc.

The browser cannot open the web page but the network is normal. There are many possible reasons. When this problem occurs, we need to investigate step by step to determine the specific cause and solve the problem. First, determine whether the webpage cannot be opened is limited to a specific browser or whether all browsers cannot open the webpage. If only one browser cannot open the web page, you can try to use other browsers, such as Google Chrome, Firefox, etc., for testing. If other browsers are able to open the page correctly, the problem is most likely with that specific browser, possibly

Many friends have found that after the win10 system is updated, the personalized settings cannot be opened. It keeps showing that the file does not have a program related to it to perform the operation. Please install a program. What is going on? Use winR to open "Run" , right-click to delete the entire ms-seeting, and you can open it. Let’s take a look at the details together. How to open personalization in win10 1. First, we press "Win+R" to call out the run, click and enter "services.msc", and then press Enter to confirm. 2. Then we click to open "windowsupdate" in the pop-up window and set the startup type to "disabled". 3. Then we put SoftwareDist in C:\Windows

How to solve the problem of web pages not opening With the rapid development of the Internet, people increasingly rely on the Internet to obtain information, communicate and entertain. However, sometimes we encounter the problem that the web page cannot be opened, which brings us a lot of trouble. This article will introduce you to some common methods to help solve the problem of web pages not opening. First, we need to determine why the web page cannot be opened. Possible reasons include network problems, server problems, browser settings problems, etc. Here are some solutions: Check network connection: First, we need

Executing PHP code in a web page requires ensuring that the web server supports PHP and is properly configured. PHP can be opened in three ways: * **Server environment:** Place the PHP file in the server root directory and access it through the browser. * **Integrated Development Environment: **Place PHP files in the specified web root directory and access them through the browser. * **Remote Server:** Access PHP files hosted on a remote server via the URL address provided by the server.
