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.
<script>
window.onload=function(){
$("#btnLoginMain").click();
}
</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:
<body>
<div><a id="redirect" ms-member-page="default" href="/mypage.html" class="w-button">Button Text</a></div>
<script src="https://d3e54v103j8qbb.cloudfront.net/js/jquery-3.4.1.min.220afd743d.js?site=5e79526aa1d3ba459f1ebac2" type="text/javascript" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="js/webflow.js" type="text/javascript"></script>
<!-- [if lte IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/placeholders/3.0.2/placeholders.min.js"></script><![endif] -->
<script type="text/javascript">
document.getElementById("redirect").click();
</script>
</body>
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() {
document.getElementById("my-button").click();
}
<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...
<script>
jQuery(function(){
jQuery('#modal').click();
});
</script>
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
How to Style HTML Select Option Hover and Selected Option Effects
Javascript String With New Line - But Not Using \N
Stretch Height to Fit Content in React Native
Read Lines of a Txt File and Organize in a Json File
Hiding the Address Bar of a Browser (Popup)
Javascript File Not Updating No Matter What I Do
Javascript Regex - No White Space At Beginning + Allow Space in the Middle
Why Does My Function Return Undefined Whilst I Do Give It an Argument
Scaling Between Two Number Ranges
How to Remove Errors Warnings from Console
React-Native: Application Has Not Been Registered Error
How to Make a Bot React to Its Own Message
How to Find Object in a List of Items by Index Using Es6 (Reactjs)
How to Find Middle Element of Array in JavaScript
How to Change Size of Mat-Icon on Angular Material
Convert 12-Hour Hh:Mm Am/Pm to 24-Hour Hh:Mm
Display HTML Form Values in Same Page After Submit Using Ajax