路由器WEB管理的登录对话框实现 如题!路由器WEB管理的登录对话框怎么实现?当在浏览器输入路由器IP地址后,便出现了一个登录对话框!是怎么实现的啊!希望各位知道的能提供一个用JS实现的方法!谢谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 弹出一个页面,然后把父页面关闭!就模拟出了一个小窗口了,点击直接弹出一个对话框,web上是不可能的。 做登录页面是可以!我用的是showModalDialog!但是被浏览器给拦截了!就直接跳到首页了! div做的模拟窗口能不能在直接访问首页的时候就弹出来呢?而不是通过点击按钮的方式弹出来! 直接似乎不能弹出来!而直接通过点击按钮的方式能弹出模拟窗口来!我在网上找了段源码如下!<html> <head> <title>LIGHTBOX EXAMPLE</title> <style><!--#auth_dialog{display:none;position:absolute;width:300px;height:200px;border:1px #ccc solid;left:450px;top:200px--></style></head> <body><form name= "tcpip" method="post" action="/goform/form_prtsvrtcpipSet"><input type="button" value="Apply New Settings" onclick="return ShowAuthDialog();"/></form><div id=auth_dialog><p>用户名:<input type=text id=userAccount name=userAccount/></p><p>密码:<input type=password id=userPwd name=userPwd/></p><p><input type=button value="登 入" onclick="Auth();" /></p></div><script type=text/javascript> function ShowAuthDialog(){ document.getElementById('auth_dialog').style.display = 'block'; return false;//这里返回false可以让form不被提交,你也可以把submit改为button } function Auth(){ //使用Ajax处理登入过程 if(success)//返回是否登入成功 return true; return false; }</script></body> </html> 你改成这样看看那呢,加载的时候就弹出div<body onload="ShowAuthDialog()"> 服务器发送 HTTP 401 头就行了. <%@page contentType="text/html;charset=GBK" %><%String authorization= request.getHeader("Authorization"); if( authorization != null ){ sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); String parame = new String( decoder.decodeBuffer( authorization.substring( 6,authorization.length() ) ) ); String s[] = parame.split(":"); if( s.length > 0 ) { String user = s[0]; String pwd = s[1]; out.println( user +"|"+ pwd ); out.println( authorization ); out.println("<script> document.cookie.setMaxAge(1);//防止响应的用户密码存在客户端 </script>"); return; }} response.setStatus(401); response.setHeader("WWW-Authenticate", "BASIC realm=\"pwd\""); response.setHeader("Cache-Control","no-store"); response.setDateHeader("Expires",0);%> <%@page contentType="text/html;charset=GBK" %> <% String authorization= request.getHeader("Authorization"); //获取请求头Authorization部分if( authorization != null ) { sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); //BASE64解码对象 String parame = new String( decoder.decodeBuffer( authorization.substring( 6,authorization.length() ) //跳过前面6个字符("Basic "),获取后面部分 ) ); //BASE64解码 String s[] = parame.split(":"); //根据":"分割字符串,返回一个字符串数组 if( s.length > 0 ) //可有可无的验证 { String user = s[0]; //用户名 String pwd = s[1]; //密码 out.println( user +"|"+ pwd ); //演示解码过的用户名和密码 out.println( authorization ); //演示整个串 out.println(" <script> document.cookie.setMaxAge(1);//防止响应的用户密码存储在客户端 </script>"); return; } } response.setStatus(401); response.setHeader("WWW-Authenticate", "BASIC realm=\"pwd\""); //pwd是主机名,随便整 response.setHeader("Cache-Control","no-store"); //防止本页面缓存,也有防止响应的用户密码存储在客户端的作用 response.setDateHeader("Expires",0); %> 如何把代码放到文件中?然后从网页执行这个文件 javascript能获取img的src,但无法获取img的width和height???? 温度控制 动态table的td 算术问题 请教:怎么用javascript直接隐藏当前窗口的地址拦 真急!!求高手相助 今天晚上试验成功了就给分! 可以用javascript等脚本语言画一条线吗? 在分帧中传递数据的奇怪问题! 在一个包含修改数据表单 窗口里, 如何在离开窗口的时候,判断表单<from>里的数据是否已经改变, 请问如何用JS控制光标的移动? 新手求帮助!
我在网上找了段源码如下!
<html>
<head>
<title>LIGHTBOX EXAMPLE</title>
<style><!--
#auth_dialog{display:none;position:absolute;width:300px;height:200px;border:1px #ccc solid;left:450px;top:200px--></style>
</head>
<body>
<form name= "tcpip" method="post" action="/goform/form_prtsvrtcpipSet">
<input type="button" value="Apply New Settings" onclick="return ShowAuthDialog();"/>
</form>
<div id=auth_dialog>
<p>用户名:<input type=text id=userAccount name=userAccount/></p>
<p>密码:<input type=password id=userPwd name=userPwd/></p>
<p><input type=button value="登 入" onclick="Auth();" /></p>
</div>
<script type=text/javascript> function ShowAuthDialog(){
document.getElementById('auth_dialog').style.display = 'block';
return false;//这里返回false可以让form不被提交,你也可以把submit改为button
} function Auth(){
//使用Ajax处理登入过程
if(success)//返回是否登入成功
return true;
return false;
}
</script>
</body>
</html>
<body onload="ShowAuthDialog()">
<%
String authorization= request.getHeader("Authorization");
if( authorization != null )
{
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
String parame = new String(
decoder.decodeBuffer(
authorization.substring( 6,authorization.length() )
)
);
String s[] = parame.split(":");
if( s.length > 0 )
{
String user = s[0];
String pwd = s[1];
out.println( user +"|"+ pwd );
out.println( authorization );
out.println("<script> document.cookie.setMaxAge(1);//防止响应的用户密码存在客户端 </script>");
return;
}
}
response.setStatus(401);
response.setHeader("WWW-Authenticate", "BASIC realm=\"pwd\"");
response.setHeader("Cache-Control","no-store");
response.setDateHeader("Expires",0);%>
<%
String authorization= request.getHeader("Authorization"); //获取请求头Authorization部分
if( authorization != null )
{
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder(); //BASE64解码对象
String parame = new String(
decoder.decodeBuffer(
authorization.substring( 6,authorization.length() ) //跳过前面6个字符("Basic "),获取后面部分
)
); //BASE64解码
String s[] = parame.split(":"); //根据":"分割字符串,返回一个字符串数组
if( s.length > 0 ) //可有可无的验证
{
String user = s[0]; //用户名
String pwd = s[1]; //密码
out.println( user +"|"+ pwd ); //演示解码过的用户名和密码
out.println( authorization ); //演示整个串
out.println(" <script> document.cookie.setMaxAge(1);//防止响应的用户密码存储在客户端 </script>");
return;
}
}
response.setStatus(401);
response.setHeader("WWW-Authenticate", "BASIC realm=\"pwd\""); //pwd是主机名,随便整
response.setHeader("Cache-Control","no-store"); //防止本页面缓存,也有防止响应的用户密码存储在客户端的作用
response.setDateHeader("Expires",0); %>