Total Pageviews

Thursday, 26 July 2012

如何在Chrome里点击.crx超链接,显示安装提示?

 如果把crx文件放在自己的服务器上,那么下载该crx时是没有安装提示的,
需要用户手动将crx文件拖入chrome浏览器中。
Google了一下,找到了Chrome Developer's Guide中关于Hosting的说明(http://code.google.com/chrome/extensions/hosting.html)
Google Chrome considers a file to be installable if either of the following is true:
   
·The file has the content type application/x-chrome-extension
·The file suffix is .crx and both of the following are true:
        ·The file is not served with the HTTP header X-Content-Type-Options: nosniff
        ·The file is served with one of the following content types:
            ·empty string
            ·"text/plain"
            ·"application/octet-stream"
            ·"unknown/unknown"
            ·"application/unknown"
            ·"*/*"

而我的服务器返回的.crx的http response header为   
HTTP/1.1 200 OK
Date: Fri, 22 Jul 2011 08:16:44 GMT
Server: Apache
Last-Modified: Thu, 21 Jul 2011 11:38:13 GMT
ETag: "a51e404-8452-4a892c8b77340"
Accept-Ranges: bytes
Content-Length: 33874
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: text/x-fortran

于是解决方法就很简单了,我的站点是安装在apache下的,只需要在站点根目录的.htaccess中增加如下一行(注意不要改动wordpress的默认规则)。如何在其他HTTP Server中修改mime-type,请自行Google。
   
# .htaccess
AddType application/x-chrome-extension crx

然后再在Chrome里点击.crx超链接(可能需要先清除浏览器缓存),就可以看到安装提示了.