使用 JavaScript 填写另一个网站的输入字段 [英] Fill input fields of another Website using JavaScript

查看:29
本文介绍了使用 JavaScript 填写另一个网站的输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本,它会自动填充另一个网站的两个输入字段.我查看了网站,发现两个输入字段的名称为userid"和userpass".我还编写了这段非常简单的小代码以使其更易于理解.(假设 http://www.w3schools.com 有两个输入字段,名称分别为userid"和userpass"')

I am trying to write a script, that automatically fills two input fields of another website. I looked at the website an saw, that the two input fields have the name 'userid' and 'userpass'. I also wrote this very simple little piece of code to make it more understandable. (Lets say http://www.w3schools.com has two input fields with the names 'userid' and 'userpass')

<input type="button" value="Username" onClick="Start()" />
<input type="text" id="username" value="Username"/>
<input type="text" id="password "value="Password"/>

<script language="JavaScript">

function Start()
{
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;;

    window.open("http://www.w3schools.com");
}

</script>

如何传递两个变量并将它们的值填充到两个输入字段?有什么办法吗?

How can I pass the two variables and fill the value of them to the two input fields? Is there any possible way?

谢谢

推荐答案

看这个问题.

只有在它们位于同一域中时,您才能执行此操作(请参阅 相同-来源政策).否则会有一个巨大的安全问题.

You're only able to do this if they're on the same domain (see same-origin-policy). Otherwise there's a huge security issue.

这篇关于使用 JavaScript 填写另一个网站的输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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