[英]Auto filling in fields of an iframe and submitting the form using javascript
[英]Submitting and filling form without an ID in an iframe
不久前,在我的一個舊的weebly站點上(在我沒有JavaScript知識之前),我搜索了一種方法,該方法可以僅訪問我知道的頁面並自動登錄weebly。
我遇到了下面的代碼,該代碼可以滿足我的需要(稍作修改)。
<form id="formID" target="frame" method="post" action="[posturl]">
<input type="hidden" name="user" value="__" />
<input type="hidden" name="password" value="__" />
</form>
<iframe id="frame" name="frame" width="800" height="350"></iframe>
<script type="text/javascript">
// submit the form into iframe for login into remote site
document.getElementById('formID').submit();
// once you're logged in, change the source url (if needed)
var iframe = document.getElementById('frame');
*/iframe.onload = function() {
if (iframe.src != "") {
iframe.src = "";
}
}/*
</script>
現在,我需要將其用於另一個網站,問題是它需要一個表單ID,而目標頁面/表單沒有該表單。
目標頁面上的表單代碼如下所示:
<form action="[posturl]" method="post" accept-charset="ISO-8859-1">
<table border="0" cellspacing="5" cellpadding="0" class="ssi_table">
<tr>
<td align="left" width="85"><label for="user"><b>Username:</b></label> </td>
<td><input type="text" id="user" name="user" size="9" value="" class="input_text"/></td>
</tr><tr>
<td align="left"><label for="passwrd"><b>Password:</b></label> </td>
<td><input type="password" name="passwrd" id="passwrd" size="9" class="input_password"/></td>
</tr><tr>
<td><input type="hidden" name="cookielength" value="-1"/></td>
</tr>
</table>
<center><input type="submit" value="Login" value="Login" class="button_submit"/></center>
</form>
我的主要問題是,有什么方法不需要ID即可識別和提交表單,而沒有ID的情況下我該如何填寫表單?
您可以執行document.forms[.. index ..]
。 例如,如果它是文檔中的第一個表格,那么它將是
document.forms[0].submit();
我看到您的表格中還有其他字段。 你也可以瀏覽到的形式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.