使用 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.