press a button on external site with javascript

2019-01-20 04:18发布

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();

5条回答
一纸荒年 Trace。
2楼-- · 2019-01-20 04:32

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 :)

查看更多
叼着烟拽天下
3楼-- · 2019-01-20 04:33

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.

查看更多
孤傲高冷的网名
4楼-- · 2019-01-20 04:55

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

查看更多
老娘就宠你
5楼-- · 2019-01-20 04:56

NO !

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

查看更多
beautiful°
6楼-- · 2019-01-20 04:57

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()).

查看更多
登录 后发表回答