user1142908
user1142908

Reputation: 21

press a button on external site with javascript

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

Answers (5)

Leonard Lepadatu
Leonard Lepadatu

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.

  1. make a div on your page (ex. #externalDiv);
  2. set CSS attribute to hidden and display to none;
  3. use (simple way) jQuery method .load() or make your own JS method using XMLHttpRequest();
  4. load external page on your page;
  5. 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

Pavel Podlipensky
Pavel Podlipensky

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

greut
greut

Reputation: 4363

NO !

For security reasons. This kind of attack is called clickjacking! and it was used on Twitter.

Upvotes: 1

DenisPostu
DenisPostu

Reputation: 599

You can't do this with JavaScript from a webpage. You can do it from browser extension though.

Upvotes: 2

Tadeck
Tadeck

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

Related Questions