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

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

问题描述

我正在尝试创建一个 javascript,它会自动按下第三方网站上的提交按钮.基本上,如果我想自动登录一个使用 cookie 填写我的用户名和密码的站点,例如一个谷歌帐户,javascript 会自动按下提交按钮,而我不必这样做.

解决方案

我猜你正在寻找的是所有按钮都有的 .click() 方法.更详细的解释如下...

您可以在一个框架中使用带有 JavaScript 代码的 frameset,在另一个框架中使用第三方页面.例如:

<HTML><frameset rows="0,*"><!-- 您会看到脚本页面.要查看实际登录页面,请交换 * 和 0. --><frame src="http://third.party.website.com/login/page.htm" name="theirframe"/><frame src="myscript.html" name="myframe"/></frameset></HTML>

如果您要登录的页面是这样的(从 Gmail 的登录页面中清除,它们有很多奇怪的换行符和空格!):

<div class="email-div"><label for="Email"><strong class="email-label">用户名</strong></label><input type="email" spellcheck="false" name="Email" id="Email" value="">

<div class="passwd-div"><label for="Passwd"><strong class="passwd-label">密码</strong></label><input type="password" name="Passwd" id="Passwd">

<input type="submit" class="g-button g-button-submit" name="signIn" id="signIn" value="登录">

那么你的脚本可能是这样的:

<!-- 你的脚本页面 (myscript.html) --><HTML><body><!-- 在此处插入自定义消息...-->正在登录......<脚本>//parent.theirframe.document.getElementById("Email").value = getemail();//parent.theirframe.document.getElementById("Passwd").value = getpass();parent.theirframe.document.getElementById("signIn").click();<正文></HTML>

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

希望这会有所帮助.

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.

解决方案

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

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>

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>

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.

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

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆