如何建立ChromeApp

來源:互聯網
上載者:User

標籤:blog   http   io   ar   sp   for   on   檔案   div   

一個ChromeAPP 包含以下內容:1. 資訊清單檔 manifest.json,列出應用的一些基本資料例如:如何啟動應用,應用的許可權等等。2. 事件處理頁面也就是我們常說的後台指令碼(background script),這個檔案管理APP的整個活動周期,這個也是你處理一些事件的監聽的地方比如如何啟動,關閉應用的表單。3.所有的代碼檔案都必須打包成一個ChromeAPP,包含HTML,CSS,JS和本地模板4.其他檔案,例片檔案也得打包至ChromeAPP 下面來建立一個APP第一步: 建立 manifest.json
{  "manifest_version": 2,  "name": "Codelab",  "version": "1",  "icons": {    "128": "icon_128.png"  },  "permissions": [],  "app": {    "background": {      "scripts": ["background.js"]    }  },  "minimum_chrome_version": "28"}
這裡需要注意的是 第一行 “manifest_version":2 這個必須要加permissions 如何是訪問網站則需要添加在這裡background 就是我們要處理的後台指令碼icons  需要提供一個正方形圖片(這個會顯示在ChromeAPP的應用列表中),大小就是 第一個參數(px) 2. 添加一個圖片也就是icons裡的圖片,注意大小要與前面的一致,例如128×128 3.建立backgroud.js
/** * Listens for the app launching then creates the window * * @see http://developer.chrome.com/apps/app.window.html */chrome.app.runtime.onLaunched.addListener(function() {  chrome.app.window.create(‘index.html‘, {    id: ‘main‘,    bounds: { width: 620, height: 500 }  });});
這個函數的意思就是在應用啟動的時候,添加一個監聽,開啟index.html這個網站(下一步我們會建立這個) 第四步建立index.html
<!DOCTYPE html><html><head>  <meta charset="utf-8"></head><body>  <h1>Hello, let‘s code!</h1></body></html>
完成上面的步驟之後,就基本完成了一個ChromeAPP的相關檔案了。 下一步就是運行了。 運行程式在Chrome的地址欄輸入chrome://extensions/  就可以開啟擴充程式列表,勾選"開發人員模式",點擊"載入正在開發的擴充程式" 開啟ChromeAPP檔案包就可以看到你的應用出現在列表中了。點擊應用下方的“啟動”就可以查看效果了。         

如何建立ChromeApp

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.