问题
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();
回答1:
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()
).
回答2:
You can't do this with JavaScript from a webpage. You can do it from browser extension though.
回答3:
NO !
For security reasons. This kind of attack is called clickjacking! and it was used on Twitter.
回答4:
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.
- make a div on your page (ex. #externalDiv);
- set CSS attribute to hidden and display to none;
- use (simple way) jQuery method .load() or make your own JS method using XMLHttpRequest();
- load external page on your page;
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 :)
回答5:
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.
来源:https://stackoverflow.com/questions/8817553/press-a-button-on-external-site-with-javascript