2012-10-28 47 views
0

我無法通過下面的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> 

也許我應該回去做漢堡... :(

+1

的多麼糟糕,這將是,如果有可能想的? 'nastysite.com?運行格式c:\'。 –

+0

當您的內聯網上無法打開自己的文本文件時,甚至會更加恐怖! :) –

+0

是否有你需要打開記事本實例的原因?記事本打開後你會發生什麼? – Ian

回答

4

不能使用JavaScript打開這樣的本地文件 - 一種安全機制,確保世界各地的網站無法在您的計算機上執行任何他們想要的程序

如果允許瀏覽器執行C:/Windows/system32/notepad.exe,什麼會阻止它呼籲format c:

+0

但它是一個Intranet應用程序... :) –

+3

@mariospolycarpou - 他們的瀏覽器不知道。 – Oded

+0

有沒有辦法告訴它? –

0

可以在記事本中打開一個文檔這樣的:

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

注:你將不得不使用Windows風格目錄分隔— \ —爲第一"notepad.exe"說法。


編輯:作爲俄德說:

如果瀏覽器被允許執行 C:/Windows/system32/notepad.exe,你會從調用 格式停止C:?

您將獲得的記事本,而不是它的一個執行的本地副本「下載」。


編輯2:也看看這個:

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

+0

在瀏覽器中使用JavaScript? – Oded

+0

我編輯了我的問題:) – 2012-10-28 16:42:11

+0

你的意思是你的答案。 – Oded