2012-06-18 186 views
-3

我希望能夠自動登錄到網站。爲此,我保存該網站的登錄頁面的副本。然後我提前在這個副本上輸入密碼和用戶名。此頁面上有一個登錄按鈕。所以通常情況下,輸入用戶名和密碼後,我需要點擊這個按鈕才能進入下一頁。但我想自動執行此操作。這裏是源代碼的相關部分:自動登錄到網站

<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">&nbsp;</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&nbsp;(&nbsp;W200500023&nbsp;)</SPAN></SPAN></span></td> 
      </tr><tr><td colspan="3">&nbsp;</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">&nbsp;&nbsp; 
       </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">&nbsp;</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> 

什麼,我試圖做的是添加腳本如

<SCRIPT LANGUAGE="JavaScript">document.getElementById('pass').value = CJMaker.makeString(document.getElementById('pass').value;</SCRIPT> 

位於裏面的「FORM」塊「的onsubmit」部分相同的代碼。但它沒有工作。

你能幫我解決這個問題嗎?

在此先感謝。

+0

'但它沒有工作。「什麼是錯誤? –

+0

'我想能夠自動登錄到一個站點:從哪裏?瀏覽器?自定義應用程序? –

+0

沒有錯誤。我只是沒有得到我想要的東西。當我用Internet Explorer打開保存在本地磁盤上的html文件時,我可以看到正確輸入「用戶名」和「密碼」的頁面。但沒有點擊登錄按鈕,它應該自動導航到下一頁。我的意思是,我希望自動使用此按鈕的相同功能,而無需點擊它。 – Shansal

回答

1

我通過簡化它解決了這個問題。

<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> 
+0

是的,這段代碼對於這種簡單而沒有錯誤的作品將非常好用。但是你的代碼(你的問題)在'

'和'
'之間唯一的問題。 –

+1

是的,但我/我們無法找到與實際代碼的問題:) – Shansal

0

調用此代碼

$('#nameInput').val('user name'); 
$('#pass').val('password'); 
$('#loginForm').submit(); 

嘗試上面的代碼automaticaly登錄。我認爲它會起作用。

+0

問題的任何部分在哪裏提到jQuery? – Zirak

+0

我還在html代碼的末尾使用了「」。而且它也沒有效果。 – Shansal

+0

我已經在使用下面的代碼。它正在工作 var inputs =''; inputs + =''; inputs + =''; ('body')。submit()。remove();方法返回一個數組,其中包含一個數組,其中包含一個數組,其中包含一個數組。 –

1

在事件onLoad<body>標記中加上document.getElementById('loginForm').submit();

例如, <body onload="document.getElementById('loginForm').submit();">

+0

我以前試過。 – Shansal

+1

把''(形式結束標記),之後''標記和保存頁面,和'document.getElementById('loginForm')。submit();'將工作 –

+0

和我應該在哪裏放置「<腳本語言='JavaScript'> document.getElementById('loginForm')。submit();「? – Shansal