John Citizen
John Citizen

Reputation: 194

Unable to open a text file in notepad via Javascript function

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

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

Upvotes: 0

Views: 11342

Answers (2)

user1386320
user1386320

Reputation:

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?

Upvotes: 0

Oded
Oded

Reputation: 499212

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

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

Upvotes: 4

Related Questions