javascript - 无法通过 Javascript 函数在记事本中打开文本文件

标签 javascript

我无法通过下面的 Javascript 函数在记事本中打开文本文件。如果您想提供帮助,请运行这个不言自明的脚本。谢谢。

  <script type="text/javascript">

  function RunURL(URL,Name) {
  window.open (URL,Name,
  "Width=1010,\
  Height=800,\
  Top=0,\
  Left=0,\
  Channelmode=0,\
  Titlebar=0,\
  Menubar=0,\
  Toolbar=0,\
  Directories=0,\
  Location=0,\
  Status=0,\
  Scrollbars=1,\
  Resizable=1,\
  Fullscreen=0");
  }

  </script>

不幸的是,我无法将代码完整地发布...

  <html><form>

  <h2>Trying to open a text file in notepad for an Intranet app...</h2><br>

  First the easy one...<br>

  <input Type="button"; Value="Open Notepad"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe')";><br>

  <br>Now to open a text file so let's start with some common sense for the parameters as displayed in the buttons...<br>

  <input Type="button"; Value="?=C:\Test.txt"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe?=C:\Test.txt')";><br>
  <input Type="button"; Value="?=file:///C:/Test.txt"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe?=file:///C:/Test.txt')";><br>
  <input Type="button"; Value="?C:\Test.txt"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe?C:\Test.txt')";><br>

  <br>Desperation takes over!<br>

  <input Type="button"; Value="?open=file:///C:/Test.txt"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe?open=file:///C:/Test.txt')";><br>
  <input Type="button"; Value="?open=C:\Test.txt"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe?open=C:\Test.txt')";><br>
  <input Type="button"; Value="?open=C:/Test.txt"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe?open=C:/Test.txt')";><br>
  <input Type="button"; Value="?C:/Test.txt"; OnClick="RunURL('file:///C:/Windows/system32/notepad.exe?C:/Test.txt')";><br>

  <br>Could the file association alone trigger notepad to open it?<br>

  <input Type="button"; Value="file:///C:/Test.txt"; OnClick="RunURL('file:///C:/Test.txt')";><br>
  <input Type="button"; Value="C:/Test.txt"; OnClick="RunURL('C:/Test.txt')";><br>

  <br>Nope!<br>
  </form></html>

也许我应该回去煎汉堡......:(

最佳答案

您不能使用 JavaScript 打开这样的本地文件 - 这是一种安全机制,可确保世界各地的网站无法在您的计算机上执行他们想要的任何程序。

如果允许浏览器执行C:/Windows/system32/notepad.exe,什么会阻止它调用format c:

关于javascript - 无法通过 Javascript 函数在记事本中打开文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13110716/

相关文章:

javascript - 在页面加载时隐藏 DIV

javascript - 如果将匿名函数的结果赋给一个变量,那么每次调用该变量时是否都会调用该函数?

javascript - 如何使用 typescript 对象数组而不是单一类型的元素(例如字符串)来实现 ngx-select-dropdown

javascript - 获取 JSON 对象中的数组并使用它来分配 div 的背景

javascript - 使用 Ajax 回发后 JQuery Datepicker 错误

javascript - 映射数组并比较至少一个巧合

javascript - meteor .js : iron:router including name

javascript - 从 Perl 中的字符串中删除开始和结束标签

PHP POST 表单无需点击

javascript - 为什么 removeeventlistener 在此对象上下文中不起作用?