Home Web Front-end JS Tutorial Baidu Popup.js pop-up box evolved version, drag and drop small frame release, compatible with IE6/7/8, Firefox, Chrome_javascript skills

Baidu Popup.js pop-up box evolved version, drag and drop small frame release, compatible with IE6/7/8, Firefox, Chrome_javascript skills

May 16, 2016 pm 06:29 PM
Pop-up box Baidu

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:
Baidu Popup.js pop-up box evolved version, drag and drop small frame release, compatible with IE6/7/8, Firefox, Chrome_javascript skills

The original Baidu’s Popup.js is there

Copy code The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 .org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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:
Copy code The code is as follows:
var C = '<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;z- index:' A ";" H "background-color:" this.color.cColor ';display:none;"></div>';

The style of the mask layer dialogBoxBG is just simple Set to height:100%, so pages with the <!DOCTYPE...> 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.
Copy code The code is as follows:

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
Copy code The code is as follows:

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:
Copy code The code is as follows:
<asp:Button ID="btnDel " runat="server" Text="Delete" OnClick="btnDel_Click" OnClientClick="return ShowConfirm(' ','Are you sure to delete?', this)" />

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.
Copy code The code is as follows:

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:
<asp:Button ID="btnDel" runat="server" OnClick="btnDel_Click" ToolTip="Delete" CssClass= "deleteBtn" OnClientClick="return subDel(this);return false;" />
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.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to skip security warnings in Baidu How to skip security warnings in Baidu Feb 23, 2024 pm 10:34 PM

How to skip security warnings in Baidu

How to use Baidu advanced search How to use Baidu advanced search Feb 22, 2024 am 11:09 AM

How to use Baidu advanced search

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

deepseek web version entrance deepseek official website entrance

After 2 months, the humanoid robot Walker S can fold clothes After 2 months, the humanoid robot Walker S can fold clothes Apr 03, 2024 am 08:01 AM

After 2 months, the humanoid robot Walker S can fold clothes

How to disable Baidu incognito mode How to disable Baidu incognito mode Feb 29, 2024 pm 03:40 PM

How to disable Baidu incognito mode

Introduction to how to obtain Baidu Xiyang Shells Introduction to how to obtain Baidu Xiyang Shells Mar 28, 2024 am 09:11 AM

Introduction to how to obtain Baidu Xiyang Shells

Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving Jun 04, 2024 pm 08:01 PM

Baidu Apollo releases Apollo ADFM, the world's first large model that supports L4 autonomous driving

ai tool recommendation ai tool recommendation Nov 29, 2024 am 11:08 AM

ai tool recommendation

See all articles