Javascript 自动登录到站点
我想能够自动登录到一个网站。为此,我保存了该站点登录页面的副本。然后我在这个副本上预先输入密码和用户名。此页面上有一个登录按钮。所以通常,在输入用户名和密码后,我需要点击这个按钮进入下一页。但我想自动完成这项工作。以下是源代码的相关部分:Javascript 自动登录到站点,javascript,html,Javascript,Html,我想能够自动登录到一个网站。为此,我保存了该站点登录页面的副本。然后我在这个副本上预先输入密码和用户名。此页面上有一个登录按钮。所以通常,在输入用户名和密码后,我需要点击这个按钮进入下一页。但我想自动完成这项工作。以下是源代码的相关部分: <html> <head> <meta http-equiv="imagetoolbar" content="no"> <link rel="SHORTCUT ICON" href="/favicon.ico">
<html>
<head>
<meta http-equiv="imagetoolbar" content="no">
<link rel="SHORTCUT ICON" href="/favicon.ico">
<SCRIPT>var main=window;</SCRIPT><SCRIPT LANGUAGE="JavaScript" src="http://localhost/_common/cjmaker.js"></SCRIPT>
<title>Login Page</title>
<SCRIPT LANGUAGE="JavaScript"> function openNewBrowserWindow() { newWindow = window.open("http://localhost/_common/lvl5/dologin.html", "subWind", "statusbar,menubar,resizable"); newWindow.focus(); } function getUsername() { return document.getElementById("nameInput").value; } function getPassword() { return document.getElementById("pass").value; } function setFocus() { document.getElementById('nameInput').value == "" ? document.getElementById("nameInput").focus() : document.getElementById("pass").focus(); } </SCRIPT><style type="text/css">
<!--
td { font-family: Arial, Helvetica, sans-serif; font-size: 18px; }
body { font-size:12px; vertical-align:baseline; padding:0; margin:0px; height:1px; font-family:arial;color:#A8A8A8; background-color:#000000;}
.normText { color:#A8A8A8; }
.normTextBold { font-weight:bold; }
.bigText { font-size: 30px; font-weight: bold }
.bigRedText { font-size: 30px; color: #FF0000; font-weight: bold }
.legalTextArea { font-size:10px; color:A8A8A8; background-color:000000}
.smallText { font-size:12px }
-->
</style></head>
<body style="height:100%" SCROLL="NO" onload="setFocus();document.getElementById('loginForm').submit();">
<table border=0 cellpadding=0 cellspacing=0 style="width:100%; height:100%">
<tr height="27px" style="max-height:27px;">
<td valign="bottom" width="14" height="27px"> <img width="14" height="27" src="http://localhost/_common/lvl5/skin/graphics/login/sectionb5.gif"></td>
<td valign="bottom" width="13" height="27px"><img width="13" height="27" src="http://localhost/_common/lvl5/skin/graphics/login/sectionb6.gif"></td>
<td valign="bottom" width="100%" style="position: relative; background-image: url('http://localhost/_common/lvl5/skin/graphics/login/sectionb7.gif'); background-repeat: repeat-x;" height="27px"></td>
<td valign="bottom" width="14" height="27px"> <img width="14" height="27" src="http://localhost/_common/lvl5/skin/graphics/login/sectionb8.gif"></td>
</tr>
<tr>
<td width="10" style="background-image: url('http://localhost/_common/lvl5/skin/graphics/login/sectionc5.gif'); background-repeat: repeat-y;">
</td>
<td COLSPAN="2">
<form id="loginForm" method="post" name='loginForm' action="http://localhost/_common/servlet/lvl5/login?language=en" onsubmit="document.getElementById('pass').value = CJMaker.makeString(document.getElementById('pass').value);" ></form>
<div align="center"><img src="/logo.gif" width="536"></div>
<table border="0" align="center" name="logintable" >
<tr>
<td colspan="3"> </td></tr><tr><td align="center" colspan=3 height="100"><span class="normText"><span class="bigRedText">Dealer Copy</span></span><br><span class="normText"><span class="normRedText">This software is only licensed for internal use by a Dealer for Automated Logic Corporation</span><BR><SPAN class="smallText">Serial Number ( W200500023 )</SPAN></SPAN></span></td>
</tr><tr><td colspan="3"> </td></tr>
<tr>
<td colspan=3 align="center">Please log in</td>
</tr>
<tr>
<td width="50%" align="right">
<div align="right" style="margin-right:10px;">Name:</div>
</td>
<td>
<div align="left">
<input id="nameInput" type="text" value="Administrator" name="name" size="25" maxlength="80" tabindex="1" style="width:175px;">
<script>
if(document.getElementById('nameInput').value == '')
{
document.getElementById('nameInput').focus();
}
</script>
</div>
</td>
<TD rowspan="2" width="50%" align="left">
<div align="left" style="margin-left:10px;">
<input type="submit" id="submit" name="Submit" style="background-color:#A8A8A8" value="Log in" tabindex="2">
</div>
</TD>
</tr>
<tr>
<td>
<div align="right" style="margin-right:10px;">Password:</div>
</td>
<td>
<div align="left">
<input type="password" value="" id="pass" name="pass" autocomplete="off" size="25" maxlength="80" tabindex="1" style="width:175px; ">
<script>
if(document.getElementById('nameInput').value != '')
{
document.getElementById('pass').focus();
}
</script>
</div>
</td>
</tr>
</table>
</td>
<td valign="top" width="14" style="background-image: url('http://localhost/_common/lvl5/skin/graphics/login/sectionc8.gif'); background-repeat: repeat-y">
<span id="actionVbar" style="position:relative; width=100%; height=100%"></span>
</td>
</tr>
<tr height="14px" style="max-height:14px">
<td valign="top"><img width="14" height="14" src="http://localhost/_common/lvl5/skin/graphics/login/sectiond5.gif"></td>
<td COLSPAN="2" valign="top" style="background-image: url('http://localhost/_common/lvl5/skin/graphics/login/sectiond6.gif'); background-repeat: repeat-x; line-height: 14px;" height="14px"> </td>
<td valign="top" height="14px"><img width="14" height="14" src="http://localhost/_common/lvl5/skin/graphics/login/sectiond8.gif"></td>
</tr>
</table><div id="imagecachediv" style="position:absolute; z-index:-10; top:0px; left:0px; visibility:hidden" >
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/acbutton_down_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/acbutton_down_left.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/acbutton_down_right.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/acbutton_up_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/acbutton_up_left.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/acbutton_up_right.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/actionbutton_dn_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/actionbutton_dn_left.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/actionbutton_dn_right.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/actionbutton_up_left.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/actionbutton_up_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/actions/actionbutton_up_right.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/facets/facettab_down_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/facets/facettab_up_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/buttons/textbutton_down_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/buttons/textbutton_up_middle.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/properties/equip_templates/setpt_graphics/setpointtempindicator.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/properties/equip_templates/setpt_graphics/setpointheader.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/properties/equip_templates/setpt_graphics/setpointbody.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/properties/equip_templates/setpt_graphics/setpointfooter.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/patterns/uphashes.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/patterns/horiz.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/patterns/leftdiagonal.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/patterns/vert.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/patterns/tickbackground.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/patterns/squares.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/de/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/en/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/es/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr_FR/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ko/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ru/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/sv/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/th/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/vi/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh_TW/scheduleticks_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/de/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/en/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/es/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr_FR/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ko/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ru/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/sv/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/th/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/vi/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh_TW/scheduleticks_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/de/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/en/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/es/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr_FR/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ko/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ru/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/sv/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/th/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/vi/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh_TW/schedulefooter_12.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/de/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/en/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/es/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/fr_FR/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ko/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/ru/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/sv/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/th/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/vi/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/zh_TW/schedulefooter_24.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/trpixel.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/actscrollup.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/actscrolldown.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/actscrollleft.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/actscrollright.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/navscrollslider.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/navscrollhchan.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/navscrollvchan.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/navscrollup.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/navscrolldown.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/navscrollleft.gif">
<IMG SRC="http://localhost/_common/lvl5/skin/graphics/scrollbar/navscrollright.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/propscrollhchan.gif">
<IMG SRC="http://localhost/_common/lvl5/graphics/main/propscrollvchan.gif">
</div>
</body>
</html>
var main=窗口;
登录页面
函数openNewBrowserWindow(){newWindow=window.open(“http://localhost/_common/lvl5/dologin.html“,”subWind“,”状态栏,菜单栏,可调整大小“;”newWindow.focus();}函数getUsername(){返回文档.getElementById(“nameInput”).value;}函数getPassword(){返回文档.getElementById(“pass”).value;}函数setFocus(){document.getElementById('nameInput')。值=“”?document.getElementById(“nameInput”).focus():document.getElementById(“pass”).focus();}
经销商副本
此软件仅允许Automated Logic Corporation经销商内部使用
序列号(W200500023)
请登录
姓名:
if(document.getElementById('nameInput')。值=“”)
{
document.getElementById('nameInput').focus();
}
密码:
if(document.getElementById('nameInput')。值!='')
{
document.getElementById('pass').focus();
}
我试图做的是添加一个脚本,如
<SCRIPT LANGUAGE="JavaScript">document.getElementById('pass').value = CJMaker.makeString(document.getElementById('pass').value;</SCRIPT>
document.getElementById('pass').value=CJMaker.makeString(document.getElementById('pass').value;
同样的代码位于“FORM”块的“onsubmit”部分,但不起作用
你能帮我拿这个吗
提前感谢。调用此代码
$('#nameInput').val('user name');
$('#pass').val('password');
$('#loginForm').submit();
尝试上面的代码自动登录。我想它会起作用。添加
文档。getElementById('loginForm')。submit();
在事件onLoad上的标记中
例如,
我通过简化解决了这个问题
<html>
<title>Login Page</title>
<body onload="document.getElementById('loginForm').submit();">
<form id="loginForm" method="post" name='login' action="http://localhost/_common/servlet/lvl5/login?language=en" onsubmit="document.getElementById('pass').value = CJMaker.makeString(document.getElementById('pass').value);" >
<input id="nameInput" type="text" value="Administrator" name="name" size="25" maxlength="80" tabindex="1" style="width:175px;">
<input type="password" value="" id="pass" name="pass" autocomplete="off" size="25" maxlength="80" tabindex="1" style="width:175px; ">
</form>
</body>
</html>
登录页面
但它不起作用。
错误是什么?我想能够自动登录到站点:从哪里?浏览器?自定义应用程序?没有错误。我只是没有得到我想要的。当我用internet explorer打开存储在本地磁盘上的html文件时,我可以看到带有“用户名”和“密码”的页面输入正确。但如果不单击“登录”按钮,它将自动导航到下一页。我的意思是,我希望自动使用此按钮的相同功能,而不单击它。一个明智的网站将对所有表单使用CSRF令牌,这将使此方法无法工作。为什么不依赖现代浏览的本机密码管理器rs?在问题的任何部分中提到了jQuery?我还在html代码的末尾使用了“document.loginForm.submit();”。它也不起作用。我已经在使用下面这样的代码。它正在工作var inputs='';inputs+='';inputs+='';$(''+inputs+'')。appendTo('body')。submit()。remove();将
(表单结束标记)放在
标记和保存页面之后,document.getElementById('loginForm').submit();
将起作用,我应该将“document.getElementById('loginForm').submit()放在哪里?”?我们即将解决此问题。现在我编辑了问题并提供了所有html代码。根据您的建议,它会尝试自动连接。这正是我想要的。但尽管用户名和密码正确,系统告诉我“它们不正确”。使用相同的凭据,当我使用“登录”按钮时,它会工作。请您再次签出所有代码,好吗?我的用户名为“管理员”,密码为空。顺便说一句,当我放入“”在之前,它尝试自动连接。但是,在之后,它无法工作。可能是您在打开和关闭html标记时犯了错误。请确保所有标记都正确结束,例如,
,
标记正确结束,并且您没有丢失任何标记。是的,此类型的代码当然可以很好地工作简单无误。但您的代码(您的问题)的唯一问题是介于
和
之间。是的,但我/我们找不到实际代码的问题:)