Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用javascript将txt文件自动下载到计算机上_Javascript_Python_Windows_Html - Fatal编程技术网

如何用javascript将txt文件自动下载到计算机上

如何用javascript将txt文件自动下载到计算机上,javascript,python,windows,html,Javascript,Python,Windows,Html,我构建了一个使用HTML5函数的HTML页面 JavaScript将经度、纬度和精度写入屏幕, 但我正在寻找一种方法,将这些数据放入一个文本文件中,并自动下载到我的计算机(Windows7)中的一个特定目录中,以便Python程序稍后读取 <script type="text/javascript"> function showLocation(position) { var latitude = position.coords.latitude;

我构建了一个使用HTML5函数的HTML页面

JavaScript将经度、纬度和精度写入屏幕,
但我正在寻找一种方法,将这些数据放入一个文本文件中,并自动下载到我的计算机(Windows7)中的一个特定目录中,以便Python程序稍后读取

  <script type="text/javascript">
    function showLocation(position) {
       var latitude = position.coords.latitude;
       var longitude = position.coords.longitude;
       var accuracy = position.coords.accuracy;
       document.write("LAT:" + latitude + "_LON:" + longitude+ "_ACU:" + accuracy);

    }

    function errorHandler(err) 
    {
        var x
        switch(error.code) 
        {
            case error.PERMISSION_DENIED:
                x = "User denied the request for Geolocation."
                break;
            case error.POSITION_UNAVAILABLE:
                x = "Location information is unavailable."
                break;
            case error.TIMEOUT:
                x = "The request to get user location timed out."
                break;
            case error.UNKNOWN_ERROR:
                x = "An unknown error occurred."
                break;
        }
        document.write(x)
    }   
     function getLocation(){
        if(navigator.geolocation){
           // timeout at 60000 milliseconds (60 seconds)
           var options = {timeout:60000,enableHighAccuracy:true};
           navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
        }

        else{
           alert("Sorry, browser does not support geolocation!");
        }
     }

  </script>

功能显示位置(位置){
变量纬度=位置坐标纬度;
var经度=position.coords.longitude;
var精度=位置坐标精度;
文件。书写(“纬度:+纬度+”_-LON:+经度+“_-ACU:+精度”);
}
函数errorHandler(err)
{
变量x
开关(错误代码)
{
案例错误。权限被拒绝:
x=“用户拒绝了地理定位请求。”
打破
案例错误。位置不可用:
x=“位置信息不可用。”
打破
大小写错误。超时:
x=“获取用户位置的请求超时。”
打破
案例错误。未知错误:
x=“发生未知错误。”
打破
}
文件编写(x)
}   
函数getLocation(){
if(导航器.地理位置){
//60000毫秒(60秒)时超时
var选项={timeout:60000,enableHighAccurance:true};
navigator.geolocation.getCurrentPosition(showLocation、errorHandler、options);
}
否则{
警报(“对不起,浏览器不支持地理位置!”);
}
}

您需要进行提交表单或执行ajax调用。据我所知,这不能在客户端用纯javascript实现。如果您喜欢python,那么可以使用python web框架,如


这里的主要问题是客户机和服务器之间的差异。你真的不希望人们能够从你托管的网站向你的计算机写入文件

你什么意思@inquisitiveIdiot@inquisitiveIdiotOP没有从internet下载文件。他试图保存javascript生成的数据。@tdelaney啊,我现在明白了。撤回先前的反对意见。我的回答是否涵盖了他试图做的事情的问题?要清楚。是否要将文件保存在运行浏览器的计算机上,而不是服务器上?假设它们是不同的机器是的,文件将保存在运行浏览器的客户端计算机上非常感谢!我会调查的