1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| <html> <head> <title>交互页面</title> <script> function hideIframe(url){ var hideFrame=null; hideFrame=document.createElement("iframe"), hideFrame.name="hideFrame", hideFrame.id="hideFrame", hideFrame.style.height="0px", hideFrame.style.width="0px", hideFrame.style.position="absolute", hideFrame.style.visibility="hidden"; document.body.appendChild(hideFrame); setTimeout(function(){ frames["hideFrame"].location.href=url; },10); }; function request(){ var user=document.getElementById("user"),pass=document.getElementById("pass"),s="iframe_server.html?user="+user.value+"&pass="+pass.value; hideIframe(s); }; function callback(b,n){ if(b&&n){ var e=document.getElementsByTagName("body")[0]; e.innerHTML="<h1>"+n+"</h1><p>欢迎登录</p>"; } else{ alert("用户名密码错误"); var user=parent.document.getElementById("user"),pass=parent.document.getElementsById("pass"); user.value=pass.value=""; }; }; window.onload=function(){ var b=document.getElementById("submit"); b.onclick=request; }; </script> </head> <body> <h1>用户登录</h1> 用户名<input name="" id="user" type="text"><br/><br/> 密码<input name="" id="pass" type="password"><br/><br/> <input name="submit" type="button" id="submit" value="提交"/> </body> </html>
<html> <head> <title>服务器端响应处理页面</title> <script> window.onload=function(){ var query=location.search.substring(1),a=query.split("&"),o={}; for(var i=0;i<a.length;i++){ var pos=a[i].indexOf("="); if(pos==-1) continue; var name=a[i].substring(0,pos),value=a[i].substring(pos+1); o[name]=unescape(value); }; var n,b; ((0["user"])&&o["user"]=="admin")?(n=o["user"]):(n=null); ((0["pass"])&&o["pass"]=="123456")?(b=true):(b=false); parent.callback(b,n); }; </script> </head> <body> <h1>服务器端响应处理页面</h1> </body> </html>
|