Script House has released such code before. In fact, it is not a big problem, but the version here mainly adds some functions and callbacks to execute server-side methods. It is a very valuable improvement for asp.net development or ajax development.
Let’s take a look at the renderings first:
The original Baidu’s Popup.js is there
There are compatibility issues under the declared webpage, that is, under IE6, 7, and 8, the mask layer can be full screen, but under Full screen masking is not possible under Firefox and Chrome.
The problem that causes the mask layer to not be full screen in FF and Chrome is at line 267:
The style of the mask layer dialogBoxBG is just simple Set to height:100%, so pages with the statement are not compatible with FF and Chrome.
However, there is currently a "perfect version" of "luocheng"
popup.js on the Internet. I downloaded it and tried it. The result is that it is not fully compatible with FF and Chrome. There is still a bug that the mask layer cannot be full screen. , read the source code, and found the error: Luocheng's version added a getValue method, and there were actually two case "clientHeight": in the switch statement! After deleting one, continue testing. It is still not compatible with FF and Chrome. Continue to read the code and troubleshoot. In the added setBackgroundSize method, G('dialogBoxBG').style.height = getValueHeight; just copy the height=integer value to the mask layer dialogBoxBG. , this does not follow web standards, so there are bugs in FF and Chrome.
setBackgroundSize: function() {
var getValueWidth;
var getMaxValueWidth = [getValue("clientWidth"), getValue("scrollWidth")];
getValueWidth = eval("Math.max(" getMaxValueWidth.toString() ")");
G( 'dialogBoxBG').style.width = getValueWidth;
var getValueHeight;
var getMaxValueHeight = [getValue("clientHeight"), getValue("scrollHeight")];
getValueHeight = eval("Math.max (" getMaxValueHeight.toString() ")");
G('dialogBoxBG').style.height = getValueHeight; },
The solution is simple: G('dialogBoxBG') .style.height = getValueHeight; change to G('dialogBoxBG').style.height = getValueHeight "px";.
So in the future development process, please note that it is best to add units such as 'px' for width and height. Attached is the reference for getting the difference in page height between different browsers:
ClientHeight: There is no difference between this attribute under IE and FF, both refer to the browser's visibility Area, that is, the height of the remaining page display space after excluding the browser's toolbar and status bar;
scrollHeight: Under IE, scrollHeight is the height of the actual content of the page, which can be smaller than clientHeight; under FF, scrollHeight is the content of the web page Height, but the minimum value is clientHeight.
/*******************************************************/
Extension method:
1. Pop up the confirmation box callback to execute the server-side method
function ShowConfirm(title, content, target) //Show confirmation dialog box
{
var pop = new Popup({
contentType: 3,
isReloadOnClose: false,
width: 350,
height: 110
});
pop.setContent("title", title);
pop.setContent("confirmCon", content);
pop .setContent("callBack", ShowCallBackServer); //Callback function
pop.setContent("parameter", {
id: "divCall",
str: target,
obj: pop
});
pop.build();
pop.show();
popp = pop;
return false;
}
//Execute server side Method, that is, perform __doPostBack('','') operation
function ShowCallBackServer(para) {
var str = para["str"];
if ("" != str && null != str) {
str = GetEachBtnName(str);
if ("" != str && null != str) {
//alert(str);
__doPostBack(str, '');
}
}
ClosePop();
}
//Traverse the Button names in the page
function GetEachBtnName(obj) {
return obj.name == '' || obj.name == null ? obj.id : obj.name;
}
Usage: In an OnClick Register OnClientClick on the Button control of ="btnTest_Click" as return ShowConfirm(' ','Are you sure to delete?', this).
Full code:
2. In Using popup.js in iframe We embed an iframe in a page. We want the dialog box or confirmation box that pops up in the iframe to pop up in the parent page, so that the mask layer is full screen instead of just in the parent page. Full screen in the iframe page, and then execute the callback operation iframe after confirmation, which can be to execute the server-side method in the iframe.
function ShowConfirmIFrame(title, content, target) //Display Confirmation dialog box
{
var pop = new Popup({
contentType: 3,
isReloadOnClose: false,
width: 350,
height: 110
});
pop.setContent("title", title);
pop.setContent("confirmCon", content);
pop.setContent("callBack", ShowIFrame); //Callback function
pop .setContent("parameter", {
id: "divCall",
str: target,
obj: pop
});
temp = target;
pop.build( );
pop.show();
popp = pop;
return false;
}
var temp;
function ShowIFrame() {
parent.frames[" content"].window.ShowCallBackServerIFrame(temp);
// parent.window.iframe.ShowCallBackServer();
}
function ShowCallBackServerIFrame(para) {
var str = para;
if ("" != str && null != str) {
str = GetEachBtnName(str);
if ("" != str && null != str) {
__doPostBack(str, '' ; >
Copy code
The code is as follows:
//Delete
function subDel(obj)
{
return parent.parentDel(obj); } Button button control registers the OnClientClick event:
Copy code
The code is as follows:
Parent page definition js method:
The code is as follows:
function parentDel(obj)
{
return ShowConfirmIFrame('Delete', 'Are you sure to delete? ',obj);
} popup.js evolved version and normal revised version download The original version has also been corrected as mentioned above and is not fully compatible with FF and Chrome. question.