自动登录第三方网站的Javascript [英] Javascript to automatically login to third party site

查看:1281
本文介绍了自动登录第三方网站的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个JavaScript,该JavaScript将自动按第三方网站上的提交按钮。基本上,如果我想使用包含用户名和密码的Cookie自动登录到站点,例如Google帐户,则javascript将自动按提交按钮,而无需我这样做。

I am trying to create a javascript that will automatically press a submit button on a third party website. Basically, if I wanted to automatically log in to a site with a cookie filling in my username and password, for example a google account, the javascript would automatically press the submit button without me having to do it.

推荐答案

我猜您正在寻找的是所有按钮都具有的 .click()方法。下面是更详细的说明...

I guess what you're looking for is the .click() method that all buttons have. A more detailed explanation is below...

您可以将框架集与一帧JavaScript代码一起使用,另一个第三方页面。例如:

You can use a frameset with your JavaScript code in one frame and the third party page in another. For example:

<!-- 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>

如果您要登录的页面是这样的(从Gmail的登录页面清除后,

And if the page you want to login to is like this (cleaned up from Gmail's login page, they have a lot of oddly-placed newlines and spaces!):

<!-- 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">

然后您的脚本可能是这样的:

Then your script would probably be something like this:

<!-- 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>

如果您的浏览器告诉您 ID为电子邮件的元素不存在或例如,您的浏览器可能在登录页面之前加载了脚本页面。在这种情况下,您必须将登录页面放在自定义页面中名为 iframe 的页面中,并将脚本放在 iframe 在页面正文中。如果您确实这样做了,此页面将帮助您访问 iframe 的内容。

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.

希望这会有所帮助。

这篇关于自动登录第三方网站的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆