Reputation: 21
is there a way to press a button on external site with javascript and/or jquery? Like I open a new window like this:
windowObjectReference = window.open("http://some_site.html","name");
Then I want to press a button on this site. Something like this:
windowObjectReference.button.click();
Or:
name.button.click();
Upvotes: 2
Views: 5742
Reputation: 646
is there a way to press a button on external site with javascript and/or jquery?
I know that I'm late at party but YES, Unfortunately it is and is a quite simple way.
click on button you wish
$('#externalDiv').load('http://www.externalPage.com', function(){$('#externalPageButtonId').click();});
Can not doge by something if you don't know how it's work :)
Upvotes: 1
Reputation: 8269
You are not allowed to do so because of SOP. Any trick to force user to perform click on your behalf will be considered as clickjacking attack and could lead to bad consequences.
Upvotes: 0
Reputation: 4363
NO !
For security reasons. This kind of attack is called clickjacking! and it was used on Twitter.
Upvotes: 1
Reputation: 599
You can't do this with JavaScript from a webpage. You can do it from browser extension though.
Upvotes: 2
Reputation: 137320
It would be a huge security violation if a browser would let you do that from the script placed on your own website.
So, no, this cannot be done, and should not be possible.
But...
If both sites belong to you (you have access to their code), you can pass a parameter (eg. as a hash within URL), then the target website may read it and fire the event you mentioned (name.button.click()
).
Upvotes: 5