Ajax Landing box to achieve the pop-up layer login effect

Source: Internet
Author: User
  code is as follows copy code

Var xmlHttp;
Function Createxmlhttprequest ()
{
    try
    {
   & nbsp;    xmlHttp = new ActiveXObject ("Msxml2.xmlhttp");
   }
    catch (E)
    {
        try
        {
             XmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
       }
        catch (SC)
        {
            xmlHttp = null;
       }
   }

    if (!xmlhttp && typeof XMLHttpRequest!= "undefined")
    {
 & nbsp;      xmlHttp = new XMLHttpRequest ();
   }
    return xmlHttp;
}
Function Showdiv ()
{
    var iwidth = document.documentElement.clientWidth;
    var iheight = document.documentElement.clientHeight;
    var bgobj = document.getElementById ("DIVBG");
    bgObj.style.cssText = "Position:absolute;left:0px;top:0px;width:" +iwidth+ "Px;height:" + Math.max (Document.body.clientHeight, iheight) + "Px;filter:alpha (opacity=30); Opacity:0.3;background-color: #000000 ; z-index:1; ";

Get event Events object for compatibility with IE and Firefox
function GetEvent ()
{
return Window.event | | Arguments.callee.caller.arguments[0];
}
document.getElementById (' Popdiv '). style.display= ' block ';
document.getElementById (' DIVBG '). style.display= ' block ';
}

function Closediv ()
{
document.getElementById (' Popdiv '). style.display= ' None ';
document.getElementById (' DIVBG '). style.display= ' None ';
}

function Readpdf (fdf_id)
{
var url = "Readpdf.aspx?login=false&id=" + fdf_id + "&r=" + math.random ();
Start_login (URL);
}
function Subscribe ()
{
var url = "Subscribe.aspx?" Subscribe=true&login=false&r= "+ math.random ();
Createxmlhttprequest ();
Xmlhttp.onreadystatechange = Handlestate_subscribe;
Xmlhttp.open ("Get", url,true);
Xmlhttp.send (NULL);
}
function Start_login (URL)
{
Createxmlhttprequest ();
Xmlhttp.onreadystatechange = Handlestate_login;
Xmlhttp.open ("Get", url,true);
Xmlhttp.send (NULL);
}
function Handlestate_login ()
{
if (xmlhttp.readystate==4)
{
if (xmlhttp.status==200)
{
var j = XmlHttp.responseText.parseJSON ();
if (J.islogin = = "false")
{
alert (J.reason);
Showdiv ();
}
Else
{
Debugger
Closediv ();
if (J.exitfile = = "true")
{
alert (J.filepath);
Top.location.href = "http://" + window.location.host + "/" +j.filepath;
}
Else
{
if (J.reason = "")
{
alert (J.filepath);
}
Else
{
alert (J.reason);
}
}
}
}
}
}

function Handlestate_subscribe ()
{
if (xmlhttp.readystate==4)
{
if (xmlhttp.status==200)
{
var j = XmlHttp.responseText.parseJSON ();
if (J.islogin = = "false")
{
alert (J.reason);
Showdiv ();
}
Else
{
alert (J.reason);
Closediv ();
}
}
}
}

function Pop_login ()
{
var UserName = document.getElementById ("Pop_username"). Value;
if (username.length = 0)
{
Alert ("Please enter user name");
return false;
}
var PassWord = document.getElementById ("Pop_password"). Value;
if (password.length = 0)
{
Alert ("Please enter a password");
return false;
}
if (username.length > 0 && password.length > 0)
{
var url = "Readpdf.aspx?" Login=true&username= "+ UserName +" &password= "+ PassWord +" &r= "+ math.random ();
Start_login (URL);
}
}

function Subscribe_login ()
{
var UserName = document.getElementById ("Pop_username"). Value;
if (username.length = 0)
{
Alert ("Please enter user name");
return false;
}
var PassWord = document.getElementById ("Pop_password"). Value;
if (password.length = 0)
{
Alert ("Please enter a password");
return false;
}
if (username.length > 0 && password.length > 0)
{
var url = "Subscribe.aspx?" Subscribe=true&login=true&username= "+ UserName +" &password= "+ PassWord +" &r= "+ math.random ();
Createxmlhttprequest ();
Xmlhttp.onreadystatechange = Handlestate_subscribe;
Xmlhttp.open ("Get", url,true);
Xmlhttp.send (NULL);
}
}


Call method

The code is as follows Copy Code

<a href= "Javascript:showdiv ();" > Login </> You can do it.

After the aspx file, you just have to set the session value to the normal login and return to the 1,0 state.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.