Unable to open a text file in notepad via Javascript function - Stack Overflow

I'm unable to open a text file in notepad via the Javascript function below. If you'd like to

I'm unable to open a text file in notepad via the Javascript function below. If you'd like to help please run this self explanatory script. Thanks.

  <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>

Unfortunately I can't post the code in one piece...

  <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 mon 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>

Maybe I should go back to flipping burgers... :(

I'm unable to open a text file in notepad via the Javascript function below. If you'd like to help please run this self explanatory script. Thanks.

  <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>

Unfortunately I can't post the code in one piece...

  <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 mon 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>

Maybe I should go back to flipping burgers... :(

Share Improve this question asked Oct 28, 2012 at 16:31 John CitizenJohn Citizen 1941 gold badge2 silver badges10 bronze badges 3
  • 1 Think of how bad this would be if it was possible? nastysite.?run=format c:\ . – Marc B Commented Oct 28, 2012 at 16:34
  • Even scarier when you can't open your own text files on your Intranet! :) – John Citizen Commented Oct 28, 2012 at 16:37
  • Is there a reason why you need to open an instance of Notepad? And what do you expect to happen after Notepad is opened? – Ian Commented Oct 28, 2012 at 17:51
Add a ment  | 

2 Answers 2

Reset to default 4

You can't use JavaScript to open local files like this - a security mechanism that ensures that websites around the world can't execute any program they want on your puter.

If the browser were allowed to execute C:/Windows/system32/notepad.exe, what would stop it from calling format c:?

You can open a document in Notepad like this:

RunURL('C:/Windows/system32/notepad.exe C:\Test.txt')

Note: You will have to use Windows style directory separator — \ — for first "notepad.exe" argument.


Edit: As Oded said:

If the browser were allowed to execute C:/Windows/system32/notepad.exe, what would stop it from calling format c:?

You will get a "Download" of a local copy of notepad, and not an execution of it.


Edit 2: Also take a look at this:

How can I run a program or batch file on the client side?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744369252a4570864.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信