js window窗口大小,定位,及传值

本示例主要实现如下效果
1.利用preLogin页面做为过度
  用window.open()设置并打开login页面
  同时关闭preLogin
2.用login页面 访问xml档 进行用户验证
  通过验证后 用window.location.href进入index页面
  并将用户名称传入index页面
说明:
(本次示例有部分代码 来源于互联网上
在此向原作者表示感谢
是他们的无私分享 让我们更快的进步)
============

示例代码如下:
+++++++++++++
preLogin.htm
+++++++++++++

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
<title>预进入页面</title>
</head>
<body>
<script language="javascript">
    window.open(
"login.htm","welcome","dependent=no,location=no,height=200,width=300,left=300,top=300,");
    window.opener 
= null;
    window.close();
</script>
</body>
</html>

++++++
login.htm
++++++
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
<title>欢迎登陆</title>
    
    
<script type="text/javascript" language="javascript">
    
    
function btnLogin()
    
{
        
//
        var currUserID = document.all.txtUserID.value;
        
var currUserPWD = document.all.txtUserPWD.value;
        
//
        var xmlDoc = new ActiveXObject('MSXML2.DOMDocument');
        xmlDoc.async 
= false;
        xmlDoc.load(
"../xml/user.xml");
        
//
        userNode = xmlDoc.selectSingleNode("/users/user[userID='"+currUserID+"']");
        
if(userNode != null)
        
{
            
var userID = userNode.childNodes(0).text;
            
var userPWD = userNode.childNodes(1).text;
            
if( (userID != currUserID) || (userPWD != currUserPWD) )
            
{
                alert(
"用户密码输入错误");
            }

            
else
            
{                
                window.location.href 
= "index.htm?currUserID="+currUserID;
                window.moveTo(
180,90);
                window.resizeTo(
700,600); 
                                          
            }

        }
       
        
else
        
{
            alert(
"用户名称输入错误");
        }
       
       
    }

    
    
</script>
</head>
<body bgcolor="silver" >
    
<br />
    
<br />
<table align="center" bgcolor="silver">
<thead title="欢迎登陆"></thead>
<tr>
<td>用户名称</td>
<td>
    
<input id="txtUserID" type="text" maxlength="20" />
</td>
</tr>
<tr>
<td>用户密码</td>
<td>
    
<input id="txtUserPWD" type="password" maxlength="20" style="width: 149px" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
    
<input id="btnLogin" type="button" value="登陆" onclick="btnLogin();" />
    
&nbsp; &nbsp; &nbsp;
    
<input id="btnExit" type="button" value="取消" onclick="self.close();" />
</td>
</tr>
</table>
</body>
</html>

+++++++++
index.htm
+++++++++
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
<title>DailyTips主界面</title>
    
<script language="javascript" type="text/javascript">
    
    
function Request(strName) 
    

        
var strHref = window.document.location.href; 
        
var intPos = strHref.indexOf("?"); 
        
var strRight = strHref.substr(intPos + 1); 
         
        
var arrTmp = strRight.split("&"); 
        
for(var i = 0; i < arrTmp.length; i++
        

            
var arrTemp = arrTmp[i].split("="); 
             
            
if(arrTemp[0].toUpperCase() == strName.toUpperCase()) 
                
return arrTemp[1]; 
        }
 
        
return ""
    }
 
    
    
var currUserID = Request("currUserID");
    document.title 
= currUserID+" DailyTips"  

    
</script>
</head>
<body>
</body>
</html>

posted on 2006-12-22 08:51  freeliver54  阅读(3057)  评论(3编辑  收藏  举报

导航