简体   繁体   English

使用js将登录数据发布到站点

[英]Post login data to site with js

I would like to write a small script that upon running it should fill some data in a html site that are already given. 我想编写一个小脚本,在运行时应该将一些数据填充到已经给出的html站点中。 So for example lets say the site is the stackoverflow logn page and I need to fill my username and password. 例如,假设该站点是stackoverflow登录页面 ,我需要填写用户名和密码。

Knowing that for the username we have: 知道对于用户名,我们有:

<input type="email" name="email" id="email" size="30" maxlength="100" placeholder="you@example.org">

password: 密码:

<input type="password" name="password" id="password" placeholder="********">

and data: 和数据:

data = {username:"user", password:"pass"};

our js should be something like below (correct?): 我们的js应该如下所示(正确吗?):

document.getElementById("email").value=data.username; 
document.getElementById("password").value=data.password; 

What I dont really understand is how to "post" that into the site and then hit the login button.(ajax?) Generally how to bring it together and make it a running script. 我真正不了解的是如何将其“发布”到站点中,然后单击登录按钮。(ajax?)通常是如何将其组合在一起并使其成为运行脚本。

Thanks in advance. 提前致谢。

document.getElementById("myForm").submit();

嵌入您输入的文件以HTML表单id="myForm"

If you have control over the login page domain, you could create a obscured login page, which sets login values to local storage then, loads the "regular" login page, which looks for and reads the local storage and logs in. 如果您可以控制登录页面域,则可以创建一个模糊的登录页面,该页面将登录值设置为本地存储,然后加载“常规”登录页面,该页面查找并读取本地存储并登录。

Here is a sample login page. 这是示例登录页面。

user= test password= testpw 用户= 测试密码= testpw

test login page 测试登录页面

and here is the "secret" login page, where you send the credentials via GET like this: http://shawnanderson.net/stack/secretlogin.html?userID=test&userPW=testpw 这是“秘密”登录页面,您可以通过GET这样发送凭据: http : //shawnanderson.net/stack/secretlogin.html? userID=test&userPW= testpw

secret login page 秘密登录页面

Otherwise, you could load the login page in an iframe and populate the login fields from there. 否则,您可以将登录页面加载到iframe中,然后在其中填充登录字段。

iframe example iframe示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM