我正在尝试创建一个JavaScript,它将自动按第三方网站上的“提交”按钮。基本上,如果我想使用包含用户名和密码的Cookie自动登录到站点(例如Google帐户),则javascript将自动按“提交”按钮,而无需我这样做。
我猜您正在寻找的是.click()所有按钮都有的方法。以下是更详细的说明...
您可以frameset在一个框架中使用带有JavaScript代码的框架,而在另一框架中使用第三方页面。例如:
<!-- Main page -->
<HTML><frameset rows="0,*">
<!-- You see your script page. To see the actual login page, swap the * and the 0. -->
<frame src="http://third.party.website.com/login/page.htm" name="theirframe" />
<frame src="myscript.html" name="myframe" />
</frameset></HTML>
Run Code Online (Sandbox Code Playgroud)
如果您要登录的页面是这样的(从Gmail的登录页面清除后,它们中有很多奇怪的换行符和空格!):
<!-- Third-party page -->
<div class="email-div">
<label for="Email"><strong class="email-label">Username</strong></label>
<input type="email" spellcheck="false" name="Email" id="Email" value="">
</div>
<div class="passwd-div">
<label for="Passwd"><strong class="passwd-label">Password</strong></label>
<input type="password" name="Passwd" id="Passwd">
</div>
<input type="submit" class="g-button g-button-submit" name="signIn" id="signIn" value="Sign in">
Run Code Online (Sandbox Code Playgroud)
然后您的脚本可能是这样的:
<!-- Your script page (myscript.html) -->
<HTML><body>
<!-- Insert custom message here... -->
Logging you in......
<script>
//parent.theirframe.document.getElementById("Email").value = getemail();
//parent.theirframe.document.getElementById("Passwd").value = getpass();
parent.theirframe.document.getElementById("signIn").click();
</script>
<body></HTML>
Run Code Online (Sandbox Code Playgroud)
If your browser is telling you that "The element with ID "Email" doesn't exist" or something, the your browser probably loaded your script page before the login page. In that case, you'll have to put the login page in a named iframe within your custom page and place your script after the iframe in the body of the page. If you do end up doing that, this page will help you out with accessing the iframe's content.
Hope this helps out.
| 归档时间: |
|
| 查看次数: |
16850 次 |
| 最近记录: |