press a button on external site with javascript

南楼画角 提交于 2019-11-27 07:21:48

问题


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.

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




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!