2016-08-12 6 views
0

を保存するフォルダを選択するためのオープンファイルダイアログ、「保存フォルダダイアログは」どこのファイルを保存するフォルダを選択することがポップアップする必要がありのjavascript:ダウンロードサーバーからのファイル:ファイルをダウンロードしたいファイル

私が試しました。 window.locationwindow.location.assignwidow.open機能と。 すべてが新鮮なページを開くにつながる!と任意のポップアップ「フォルダダイアログを保存する」を参照してくださいカント!

ファイル名をダウンロードする拡張子.cfgのである、ファイルがバイナリまたはJSONのいずれかになります(テキストファイル)。ファイルがバイナリまたはテキストの場合は違いがありますか?

ブラウザでユーザーのコンピュータにアクセスすることを許可されていませんJavaScriptのセキュリティ上の理由から

$(document).ready(function() { 
 

 
    $("#DownloadFile").click(function() { 
 
    // // hope the server sets Content-Disposition: attachment! 
 
    var \t urlData= window.location.protocol + "//" +  window.location.host + "/" + "download/testdown.cfg"; 
 
    alert("download file: " + urlData); 
 
    retval = fileExists(urlData); 
 
    if(retval) { 
 
     alert("file exists !!"); 
 
     window.location = 'download/testdown.cfg'; 
 
     // window.location.assign(urlData); 
 
     // window.open(urlData, 'Download'); 
 

 
    }else{ 
 
     alert("File not exists !"); 
 
    } 
 
    }); 
 

 

 

 

 

 
    function fileExists(url) { 
 
    alert(" url : " + url); 
 
    if(url){ 
 
     alert(" url : " + url); 
 
     var req = new XMLHttpRequest(); 
 
     req.open('HEAD', url, false); 
 
     req.send(); 
 
     // return req.status==200; 
 
     return true; 
 
    } else { 
 
     return false; 
 
    } 
 
    } 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table class="table table-condensed table-bordered table-striped volumes tabcenter" 
 
     style="align:center; margin:5px; width:98%"> 
 

 
    <tbody> 
 
    <tr> 
 
     <td> 
 
     <div class="row"> 
 
      <h1>Choose File Type</h1> 
 
      <label class="radio-inline"> 
 
      <input name="radioGroup" id="radio1" value="option1" type="radio"> Binary Data 
 
      </label> 
 
      <label class="radio-inline"> 
 
      <input name="radioGroup" id="radio2" value="option2" checked="" type="radio"> Json Data 
 
      </label> 
 

 
     </div> 
 
     </td> 
 

 
     <td > 
 
     <button type="submit" id="DownloadFile" >Download!</button> 
 
     </td> 
 
    </tr> 
 
    </tbody> 
 
</table>

+1

この動作を制御することはできません。 –

+0

https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1 – epascarello

答えて

関連する問題