2015-08-25 90 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

    相關問題