Javascript - Auto Click on a Button on Page Load

Automatically click button on page load

First, this is not a good approach to make the customers/users to logging in. You can use cookie or sessions to auto login your user. Still, if you want to click the button auto on web page loading you can use the below script.


use this in the header file of your html file. If you want to click the button after some time of page load use the setTimeout() function.

Auto click button on page load is not working

The autoclick is working, but it's just the fact that your anchor tag (a) is not leading the user anywhere. You probably were trying to do something like this:

<div><a id="redirect" ms-member-page="default" href="/mypage.html" class="w-button">Button Text</a></div>
<script src="" type="text/javascript" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="js/webflow.js" type="text/javascript"></script>
<!-- [if lte IE 9]><script src=""></script><![endif] -->
<script type="text/javascript">

Read more about anchor tags here.

a tags are for links, to send your user to a page. Buttons are made with the <button> tag.

Click JS button on page load

window.onload = function() {
<button id="my-button" class="configure-product configure-product-simple elementor-button" type="button" data-price="95" data-product_id="1934">Stel samen!</button>

Auto-click button element on page load using jQuery

You would simply use jQuery like so...


Use the click function to auto-click the #modal button

auto click button when javascript function is called NOT on page load or button click

Since your logic is being ran as soon as it is reached by the parser, the elements that you are trying to manipulate must already exist for you to use them. So if the element appears on the page after the function call, it will not exist in the DOM yet for you to find and click it logically. Your script will need to be after the element in the DOM. Otherwise, you could put your logic in a document ready and then it would not execute until the entire page is parsed into the DOM.

Related Topics

Leave a reply