SoFunction
Updated on 2025-04-08

JavaScript automatically clicks on links How to prevent browser access

When logging in to an Alipay account, you need to do an effect, that is, when opening the link page, you do not need to click on the link, and jump directly to the Alipay login page. In other words, you need to make an automatic click link effect.

Basically, this is used:

<body onLoad="autoclick('auto')">

<a id='auto' href=".$url."><img border='0' src='images/' /></a>

</body>

<script type="text/javascript">


 function autoclick(){

 lnk = ("auto");

 ();

  }

</script>

This can be used under IE, but not other browsers. It's still overwhelming, wasting everyone's search time.

The following is quite reliable, let's take a look first:

<body onLoad="autoclick('auto')">

<a id='auto' href=".$url."><img border='0' src='images/' /></a>

</body>

<script type="text/javascript">  1: 

function autoclick(name)

{  

  if()  

  {  

    //alert(1);

     (name).click();  

  }  

   else  

  {  

    var evt = ("MouseEvents");  

      ("click", true, true);  

    //alert(2);

    (name).dispatchEvent(evt);  

   }  

} 

</script>

This works fine in Chrome and IE, but it doesn't work in Firefox. But it's better than the first one.

There is a problem with dispatchEvent under Firefox.Here is the solution:

("me").onclick = function() {

  var card = ("card");

   if(){

    var ev = ('HTMLEvents');

    ('click', false, true);

    (ev);

   }

   else 

     ();
 }

The card element is the element with events bound. The me element is an element that wants to call the card's click event by clicking the me element. . . .

The point of the problem is that the firefox js engine needs to create an event first: var ev = ('HTMLEvents');

Then specify the event as a click event: ('click', false, true);

Finally pay the event to the card element: (ev);

card = ('id');

var ev = ('HTMLEvents');

('click', false, true);

(ev);

It can be seen that dispatchEvent is the last step in the event delegate, linking the delegate event with the called element to achieve the effect of the event calling this element.

Finally, it is recommended to use input to implement, and the following is the final solution:

<body onLoad="autoclick('auto2')">

 <input  type="hidden" onClick="javascript: = '&lt;?=$url?>' " />

</body>

<script type="text/javascript">  1: 

function autoclick(name)

 {  

  if()  

  {  

    //alert(1);

     (name).click();  

  }  

   else  

  {  

   var evt = ("MouseEvents");  

     ("click", true, true);  

    //alert(2);

    (name).dispatchEvent(evt);  

   }  
} 
</script>

The above article JavaScript automatically clicks the link to prevent browser access from being bypassed is all the content I share with you. I hope you can give you a reference and I hope you can support me more.