简体   繁体   English

使用javascript字段自动登录并填写并提交

[英]login automatically with javascript field fill and submit

We have a local https page for login. 我们有一个用于登录的本地https页面。 I want to load it from outside in an iframe and put username and password inside it then submit these two info with javascript . 我想从iframe的外部加载它,并在其中放入用户名和密码,然后使用javascript提交这两个信息。 (auto login). (自动登录)。 I mean i want the page to be logged in automatically (automatically fill the username and password then submit info on page open) here is the code that i used 我的意思是我希望页面自动登录(自动填写用户名和密码,然后在打开的页面上提交信息),这是我使用的代码

<iframe src='https://xxxxxx/login.html' name='login' id='login'></iframe>
<script language="javascript>


  parent.login.formname.username.value = 'username';
parent.login.formname.password.value = 'pass';
parent.login.formname.submit();
window.frames['login'].document.formname.submit();
</script>

I saved the code in a HTML FILE AND WHEN I OPEN IT NOTHING HAPPENS. 我将代码保存在HTML文件中,当我打开它没有发生时。 note that i can open the https page in my iframe what should i do? 请注意,我可以在iframe中打开https页面,该怎么办? is there better approach? 有更好的方法吗?

You cannot modify content of iframe with javascripts or without user involvement because of same origin policy. 由于具有相同的来源政策,因此无法使用JavaScript或没有用户参与就无法修改iframe的内容。 If your iframe directory and your iframe "showing" domain is same, then however, you can do so. 如果您的iframe目录和iframe“显示”域相同,那么您可以这样做。

http://en.wikipedia.org/wiki/Same-origin_policy http://en.wikipedia.org/wiki/Same-origin_policy

我认为更好的方法是传递用户名和特殊ID的json(不是密码,这是不安全的),您每次使用随机字符/当前时间等登录时都可以生成特殊ID。的方法,但这工作,并且很安全:)通过ID而不是用户名获取此页面。

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

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