2015-08-25 88 views

回答

0

您将遇到问题,因为您要检查的数据不在同一个域中。

但是,您可以使用类似node webkit(现在的nwjs)来通过浏览器限制。

  1. 要开始下载nodewebkit文件从以下链接您的操作系统:

http://nwjs.io/

  • 提取内容。

  • 下载JQuery并将其放置在解压缩的文件夹中(重命名文件jquery.js)。

  • 创建一个新的文本文件,添加以下内容并保存为的package.json

  • 的package.json内容:

    { 
        "main": "index.html", 
        "name": "firefoxversion", 
        "version": "1", 
        "window": { 
        "title": "latest firefox version", 
        "icon": "link.png", 
        "toolbar": true, 
        "width": 800, 
        "height":600 
        } 
    } 
    

    创建一个文件名index.html,然后保存以下内容:

    index.html内容:

    <html> 
        <head> 
         <title>Latest Firefox Version</title> 
         <meta charset="UTF-8"> 
         <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        </head> 
        <body> 
    
         <div id="result"></div> 
    
    
    
    
         <script type="text/javascript" src="jquery.js"></script> 
         <script type="text/javascript" src="main.js"></script> 
        </body> 
    </html> 
    
  • 接着创建main.js文件命名和保存下列内容:
  • main.js内容:

    var url ="http://download.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/update/win32/en-US/"; 
    
    
    var version; 
    
    $.get(url,function(data){//begin function 
    
    
    $(data).contents().find("a").each(function(){//begin each function 
    
    
    //create an array to hold the hmtl 
    var html = []; 
    
    
    if($(this).attr("href").indexOf("complete.mar" !== -1)){//begin if then 
    
    
    version = $(this).attr("href").split(".c"); 
    
    
    //start building your html to output 
    html.push("Download the latest Firefox Version " + version[0] + " below:<br>"); 
    
    //add the download button 
    html.push("<input type ='button' id ='firefox-latest' value = 'Download Firefox'>"); 
    
    
    //display the html in the #result div 
    $("#result").html(html.join("")); 
    
    
    }//end if then 
    
    
    });//end each function 
    
    
    
    
    });//end function 
    
    //on click event for #firefox-latest 
    $(document).on("click","#firefox-latest",function(){//begin on click event 
    
    //change the window location to the file for the latest firefox version 
    window.location.href = url + version[0] + ".complete.mar"; 
    
    
    });//end on click event 
    
  • 最后点击你之前提取的文件夹里面的nw.exe图标 ,你应该看到最新版本的firefox。
  • +0

    太棒了!它效果很好。 – Imsa

    +0

    现在,有没有办法使用该版本号并将其导出到文件?或者使用解析后的版本并将其添加到URL的末尾,以将其用作链接以下载文件。目标是动态查找最新版本,然后下载最新的.mar文件。 – Imsa

    +0

    不应该是一个问题我会处理它并编辑我的答案 –

    1

    简单的答案是Mozilla Release Engineering已经提供了一种下载最新版本的方法。请参阅https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt

    例如,我想要下载最新的Linux 64位美国英语版的Firefox。所以我会:

    curl -Lo firefox.tar.bz2 'https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US' 
    tar -xjf firefox.tar.bz2 
    cd firefox 
    ./firefox --version 
    

    请注意,这些是稳定版本,而不是RC或每晚。对于那些看release notes in the appropriate subfolder

    注:

    • curl命令URL由单引号(')包围,以避免的bash解释符号(&)。
    • 您可能需要在$PATH(或Windows中的%PATH%)环境变量的开头添加您下载的Firefox。
    +1

    如果您从卷曲中获得问题,请尝试在链接周围替换单引号(')与双引号(“) – jenesaisquoi

    0

    因为我必须知道许多应用程序的最新版本号,所以我创建了名为vergrabber的在线服务,它在json中提供了这些信息。 你可以试试这个免费服务http://vergrabber.kingu.pl/vergrabber.json

    相关问题