2013-05-22 104 views

回答

3

您可以使用chrome.runtime.getManifest().version獲得您的分機的當前版本。

爲了得到擴展的「最新版本」,您需要下載updates.xml,並提取版本號:

var extensionID = chrome.i18n.getMessage('@@extension_id'); 
var currentVersion = chrome.runtime.getManifest().version; 
var url = 'https://clients2.google.com/service/update2/crx?x=id%3D' + extensionID + '%26v%3D' + currentVersion; 

var x = new XMLHttpRequest(); 
x.open('GET', url); 
x.onload = function() { 
    var doc = new DOMParser().parseFromString(x.responseText, 'text/xml'); 
    // Get and show version info. Exercise for the reader. 
}; 
x.send(); 
0

如果你想定製的PHP你的要求,避免更新在extensi

<?php 

    $last_ver; 
    $googleupdate = 'http://clients2.google.com/service/update2/crx?response=updatecheck&x=id%3D__id__%26uc'; 
    $ver   = $_POST['ver']; 
    $id    = $_POST['id']; 

    //filter/control for post request very fast for this example 
    if(isset($id) && isset($ver)){ 
     if(strlen($id)>0){ 
      $urlupdate = str_replace('__id__', $id, $googleupdate); 
      $last_ver = _GetLastVersion($urlupdate); 
      if($last_ver>0 && $last_ver>$ver){ 
       echo 'New version available, v'.$last_ver; 
      }else{ 
       echo 'Your version is update'; 
      } 
     }else{ 
      echo 'Insert id for response'; 
     } 
    }else{ 
     echo 'Insert data for response'; 
    } 

    //if your server do not connect with file_get_contents() use this function 
    function getContent ($url) { 

      $ch = curl_init(); 

      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_HEADER, 0); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 

      $output = curl_exec($ch); 
      $info = curl_getinfo($ch, CURLINFO_HTTP_CODE); 

      curl_close($ch); 
      if ($output === false || $info != 200) { 
       $output = null; 
      } 
      return $output; 

    } 

    //this function return 0 if error or not content load 
    function _GetLastVersion($url){  
     try { 
      $last=0; 
      //if you have proble you can use getContent($url) 
      $xmlcontent = file_get_contents($url); 
      if($xmlcontent){ 
       $doc = new DOMDocument(); 
       $doc->loadXML($xmlcontent); 
       $items = $doc->getElementsByTagName('updatecheck'); 
       foreach ($items as $item) { 
        if($item->getAttribute('version')>0){ 
         return $item->getAttribute('version'); 
        } 
       } 
       return $last; 
      }else{ 
       return 0; 
      } 

     } catch (Exception $e) { 
      return 0; 
     }  
    } 
?> 

:每延長谷歌改變了API的時候,我建議以下

update_info.php(從您的網站)發送請求到您的網頁,現在您掌握了您的腳本,您可以決定每次回覆哪個答案

相關問題