javascript可以模拟按钮点击吗? [英] Can javascript simulate a button click?

查看:94
本文介绍了javascript可以模拟按钮点击吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个网站,如果允许宏自由运行会有问题。

I am designing a site where it would be problematic if macros were allowed to run freely.

我想到了一种通过模拟宏来制作宏的方法来自按钮点击的HTTP请求,但如果他们可以插入只是点击按钮并按照普通用户的方式继续操作的JavaScript脚本,这将是徒劳的。

I have thought of a way to stop a macro made by simulating the HTTP requests from a button click but this would be in vain if they could insert javascript scripts which just "click" the button and proceed as a normal user would.

通过模拟按钮单击,我的意思是,按下按钮,表单按钮运行与PHP代码关联。

By simulating a button click, I mean, the button is pressed and the Form the button is in runs with the php code associated with it.

逻辑告诉我javascript可以做到这一点,但我想知道,谢谢你的任何输入!

Logic tells me javascript can do this but I would like to know for sure, thank you for any input!

~Andrew

推荐答案

可以通过编程方式单击按钮。例如,您可能会有一些页面如下:

A button may be allways clicked programmatically. For example you may have some page with form like this:

<form>
    <input type="text" />
    <button>Do something</button>
    <input type="submit">
</form>

比仅打开调试cosole并输入

than it is possible just to open debug cosole and type

document.getElementsByTagName('button')[0].click();

点击按钮,或

document.getElementsByTagName('input')[1].click();

会点击表单的提交按钮,或者只是

which will click the submit button of the form, or just

document.forms[0].submit();

提交表格而不点击按钮。

to submit the form without clicking the button.

无法阻止用户在客户端上掌握JavaScript代码。您必须在服务器端添加一些验证,以防止不必要的用户操作。

There is no way to prevent user from mastering JavaScript code on client. You have to add some validation on server side in order to prevent unwanted user actions.

这篇关于javascript可以模拟按钮点击吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆