简体   繁体   English

自动点击页面加载按钮

[英]Automatically click button on page load

I'm a little stuck on creating an automatic page to press a 'log in' button which runs a javascript, submitting the form automatically isn't good enough as it simply doesn't log the user in (it's a javascript login system - as a test), instead, it will just return an error: http://prntscr.com/m1f1f6 it needs to automatically on load 'press' the log in button: http://prntscr.com/m1f1ur in order to perform the action of sending to "./main.php" which has an 'isLoggedIn' function. 我有点想创建一个自动页面以按运行javascript的“登录”按钮,自动提交表单还不够好,因为它根本无法登录用户(这是javascript登录系统-作为测试),它只会返回一个错误: http : //prntscr.com/m1f1f6它需要在加载时自动“按下”登录按钮: http : //prntscr.com/m1f1ur以执行发送到具有“ isLoggedIn”功能的“ ./main.php”的操作。

<button class="btn btn btn-block" id="btnLoginMain">Log in</button>

Thanks in advance! 提前致谢!

You do not need click there. 您不需要单击那里。 Check the source code, what happen when you click that button and replicate it in your script. 检查源代码,单击该按钮并将其复制到脚本中会发生什么。

无需单击即可登录。在按下按钮时复制并粘贴您的代码,只需在页面启动时显示它即可。

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. 首先,这不是让客户/用户登录的好方法。您可以使用Cookie或会话来自动登录用户。 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. 在html文件的头文件中使用它。 If you want to click the button after some time of page load use the setTimeout() function. 如果要在页面加载一段时间后单击该按钮,请使用setTimeout()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM