如何从 HTML 运行另一个程序
我有以下代码片段:
<html>
<head>
<title>Example of Very First PHP Script ever!</title>
</head>
<body>
<script>
function comexe(){
C:\Program Files\Notepad++\notepad++.exe C:\Documents and Settings\User\Desktop\file.txt
}
</script>
<a href="return false;" onclick="comexe()">music</a>
</body>
</html>
How can I run another program from the HTML?我做错了什么?
I have the following snippet of the code:
<html>
<head>
<title>Example of Very First PHP Script ever!</title>
</head>
<body>
<script>
function comexe(){
C:\Program Files\Notepad++\notepad++.exe C:\Documents and Settings\User\Desktop\file.txt
}
</script>
<a href="return false;" onclick="comexe()">music</a>
</body>
</html>
How can I run another program from the HTML? What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
按照评论中的要求添加此内容作为答案
您不能 - HTML 是客户端,而 javascript 是沙盒的,以保护客户端 PC 免受此影响。除了标题之外,您的脚本与 PHP 无关 - PHP 可以运行文件系统命令,但只能在服务器上运行。
Adding this as an answer, as requested in the comments
You can't - HTML is client side, and javascript is sandboxed to protect the client PC from exactly this. Apart from the title, your script has nothing to do with PHP - which can run a filesystem command, but only on the server.
从技术上讲,您可以从内联 vbscript 执行程序。您通常会在本地运行的 .hta 文件中执行此操作。
像这样的东西:
Technically you could execute a program from inline vbscript. You would normally do this in a .hta file running locally.
Something like:
你不能这样做,因为 html 和 javascript 都是客户端技术。并且有限制,使其无法访问客户端计算机的资源。
You can not do that becasue html and javascript both client side tech. and have restriction so that it can not access resource of the client machine.
如果这是一个您必须在客户端计算机上执行多次的操作,则可以实现这一点。
只需安装一个 Web 服务器(wamp 或 xamp 或您在计算机上想要的东西),然后从您的页面调用
此脚本就可以执行您想要的任何内容,如果您对本地 Web 服务器的用户设置正确的权限
,也许,如果是客户端的一次性操作必须执行仅为一次性操作安装网络服务器并不那么实用
Bertoli Stefano
If it's a operation that you have to perform many times on client machine this could be achieved.
Just install a web server (wamp or xamp or what you want on machine) and from your page call
this script can execute whatever you want if you set correct permissions on the user of local webserver
Perhaps, if is one-time operation that a client must execute is not so pratic to install a webserver only for an onetime operation
Bertoli Stefano