0

On my website, I want to access my second website programmatically and type something in my textbox.

I've tried this post, but the answer is in Swift or Objective-C.

My First website:

function typesomething() {
  window.open('https://www.example.com', '_blank').focus();
  // Now, I want to get the textbox from the second website and type this 'Types Text'
}
<button onclick="typesomething()">type something in different website</button>

Second website:

<textarea>programmatically type something from my different website</textarea>
<!-- this website is https://www.example.com -->
Green
  • 486
  • 2
  • 11
  • 31
  • 2
    JavaScript originating from domain A generally cannot make changes to a page originating from domain B. Can you imagine the chaos if any random website could make scripted changes to another one while they were loaded into a browser? – ADyson Apr 09 '21 at 15:25
  • 2
    You won't be able to do this in client-side JavaScript unless both sites are on the same domain. – phuzi Apr 09 '21 at 15:25
  • Can you just imagine what would happen if what you were trying to do were possible? What would stop me from doing it to your website? – Scott Marcus Apr 09 '21 at 15:26
  • 2
    You could accept a query parameter on your second website which would fill in the text. You need to be careful with cross site scripting so make sure you sanitize that parameter. Another option is to use https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onmessage. Both options require cooperation between the websites, you can't do it to a random website since that would be a security hole, imagine if I could do that to your bank website while you're logged in – Ruan Mendes Apr 09 '21 at 15:26
  • 3
    Take notice of the Same-origin policy! – Norbert Willhelm Apr 09 '21 at 15:27

0 Answers0