Good day. There is a code:

<html> <head> <meta http-equiv="Refresh" content="1;URL=http://site.ru"/> </head> <body> <script language="javascript" type="text/javascript"> document.location='http://site.ru'; </script> </body> </html> 

Loading site (for example site.ru). It has a link. View

 <a href="http://site2.ru">http://site2.ru</a> 

Is it possible to somehow click on this link when downloading the superior code? Thanks in advance.

1 answer 1

In JS, you can not only assign handlers to events, but also generate them yourself. In this event, the event is triggered on a par with the browser, that is, conventional browser handlers will respond to it. For example:

 var elem = document.getElementById('elem'); var event = new Event("click"); setInterval(function(){ elem.dispatchEvent(event); },5000); elem.addEventListener('click', function(){console.log('click')}); 
 <button id="elem">Автоклик</button> 

PS still recommend before you create a question, use the search.
How to click on the link?