如何从 HTML 运行另一个程序

发布于 2024-12-04 15:50:57 字数 460 浏览 3 评论 0原文

我有以下代码片段:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凤舞天涯 2024-12-11 15:50:57

按照评论中的要求添加此内容作为答案

您不能 - 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.

酷到爆炸 2024-12-11 15:50:57

从技术上讲,您可以从内联 vbscript 执行程序。您通常会在本地运行的 .hta 文件中执行此操作。

像这样的东西:

<html>

<head>
<title>Example of Very First PHP Script ever!</title>
</head>

<body>
<script language="VBScript"> 

Sub RunProgram 
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run "C:\Program Files\Notepad++\notepad++.exe C:\Documents and Settings\User\Desktop\file.txt"
End Sub

</script>

<a href="return false;" onclick="RunProgram">music</a>

</body>
</html>

Technically you could execute a program from inline vbscript. You would normally do this in a .hta file running locally.

Something like:

<html>

<head>
<title>Example of Very First PHP Script ever!</title>
</head>

<body>
<script language="VBScript"> 

Sub RunProgram 
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run "C:\Program Files\Notepad++\notepad++.exe C:\Documents and Settings\User\Desktop\file.txt"
End Sub

</script>

<a href="return false;" onclick="RunProgram">music</a>

</body>
</html>
叹梦 2024-12-11 15:50:57

你不能这样做,因为 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.

写下不归期 2024-12-11 15:50:57

如果这是一个您必须在客户端计算机上执行多次的操作,则可以实现这一点。
只需安装一个 Web 服务器(wamp 或 xamp 或您在计算机上想要的东西),然后从您的页面调用

http://localhost/nameofscript.php

此脚本就可以执行您想要的任何内容,如果您对本地 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

http://localhost/nameofscript.php

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文