0

I want to create a new window with Twitter's intent page and then insert text into a textarea. This is my code but it is not working.

var myWindow = window.open("https://twitter.com/intent/tweet");

myWindow.onload = function() {
  myWindow.document.getElementById("status").innerHTML="Hey you!!";
}
2
  • 4
    It never will - I'm guessing you're not a twitter developer, and therefore don't own the twitter.com domain, in which case your JavaScript will never be able to talk to any pages loaded from that domain. It's prevented by browsers as a security risk. Commented Nov 1, 2016 at 17:11
  • 1
    Here's the error James mentioned. Uncaught DOMException: Blocked a frame with origin "http://stackoverflow.com" from accessing a cross-origin frame. Commented Nov 1, 2016 at 17:11

1 Answer 1

3

You can't use JavaScript to modify pages on other people's websites. It would be a huge security problem if it were possible.

Read Twitter's developer documentation. It shows you how to set default text for an intent:

<a href="https://twitter.com/intent/tweet?text=Hey+you!!">…</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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