-2

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?

Thank you

user2877820
  • 287
  • 4
  • 19

2 Answers2

0

See this question.

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.

Community
  • 1
  • 1
charles
  • 547
  • 1
  • 3
  • 11
-1

You can load the website in an Iframe, and then access the fields that you need with something like this:

var name = $('iframe[name=select_frame]').contents().find('#select_name').val();
Douglas Franco
  • 591
  • 5
  • 13