【问题标题】:How to get the current working directory JavaScript?如何获取当前工作目录 JavaScript?
【发布时间】:2016-04-05 03:20:35
【问题描述】:

我正在尝试使用 JavaScript 获取当前工作目录路径。

当我从 ubuntu 执行时:$root@ubuntu:/var/test/geek# firefox /var/www/application/test.html 我在我的警报框中得到/var/www/application,而不是在我的警报框中得到/var/test/geek

我使用了 JavaScript 代码

var path=window.location.pathname
 alert(path);

以上代码给出了test.html的路径

编辑:是否可以使用 Perl 脚本? Perl-CGI?

在知道 JavaScript 无法实现后,尝试使用 Perl 脚本:

my $pwd=cwd();

并从 HTML 运行 Perl 脚本。

从 ubuntu 执行:$root@ubuntu:/var/test/geek# firefox /var/www/application/test.html

我仍然在页面中看到 /var/www/application 而不是 /var/test/geek。 Perl 可以吗?

【问题讨论】:

  • window.location.pathname 返回加载页面的路径。您无法获取用户机器上的路径(这是一个安全风险)

标签: javascript html perl


【解决方案1】:

我建议不要依赖这个。您得到的 pathname 可能不是实际路径。大多数时候,开发人员使用 routing 来隐藏实际路径。

实际的目录结构可能类似于"D:\Test\Test\Test.html",但由于路由,您会得到不同的东西。

【讨论】:

    猜你喜欢
    • 2011-06-19
    • 2014-03-10
    • 2021-01-18
    • 2015-09-02
    • 2013-11-18
    相关资源
    最近更新 更多