-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

3
  • you can't, XSS is forbidden ! Commented Oct 20, 2014 at 13:40
  • This could be done with a chrome extension, but not XSS as @micnic said. Commented Oct 20, 2014 at 13:41
  • This cannot be done as it can cause potential risks! Commented Sep 15, 2021 at 5:46

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.