| OLD | NEW |
| 1 <div id="pageData-title" class="pageData">Background Pages</div> | 1 <div id="pageData-title" class="pageData">Background Pages</div> |
| 2 <div id="pageData-showTOC" class="pageData">true</div> | 2 <div id="pageData-showTOC" class="pageData">true</div> |
| 3 | 3 |
| 4 <p> | 4 <p> |
| 5 A common need for extensions is to have | 5 A common need for extensions is to have |
| 6 a single long-running script to manage some task or state. | 6 a single long-running script to manage some task or state. |
| 7 Toolstrips don't quite fit this need, | 7 Toolstrips don't quite fit this need, |
| 8 because multiple toolstrips can be active at any one time | 8 because multiple toolstrips can be active at any one time |
| 9 (one per browser window). | 9 (one per browser window). |
| 10 Background pages to the rescue. | 10 Background pages to the rescue. |
| 11 </p> | 11 </p> |
| 12 | 12 |
| 13 <p> | 13 <p> |
| 14 The background page is similar to a toolstrip, | 14 The background page is similar to a toolstrip, |
| 15 in that it is an HTML page that runs in the extension process. | 15 in that it is an HTML page that runs in the extension process. |
| 16 The difference is that the background page exists | 16 The difference is that the background page exists |
| 17 for the lifetime of your extension, | 17 for the lifetime of your extension, |
| 18 and only one instance of it at a time is active.</p> | 18 and only one instance of it at a time is active. |
| 19 </p> |
| 20 |
| 21 <p> |
| 22 In a typical extension with a background page, |
| 23 the UI — |
| 24 toolstrips, page actions, and so on — |
| 25 is implemented with dumb views. |
| 26 When the view needs some state, |
| 27 it requests the state from the background page. |
| 28 When the background page notices a state change, |
| 29 the background page tells the views to update. |
| 30 </p> |
| 19 | 31 |
| 20 <h2 id="manifest">Manifest</h2> | 32 <h2 id="manifest">Manifest</h2> |
| 21 | 33 |
| 22 <p> | 34 <p> |
| 23 Register your background page in the extension manifest, like this: | 35 Register your background page in the extension manifest, like this: |
| 24 </p> | 36 </p> |
| 25 | 37 |
| 26 <pre>{ | 38 <pre>{ |
| 27 "name": "My First Extension", | 39 "name": "My First Extension", |
| 28 "version": "1.0", | 40 "version": "1.0", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 if (views[i].enableCheckbox) | 65 if (views[i].enableCheckbox) |
| 54 views[i].enableCheckbox(checked); | 66 views[i].enableCheckbox(checked); |
| 55 } | 67 } |
| 56 } | 68 } |
| 57 | 69 |
| 58 toolstrip.html (snippet): | 70 toolstrip.html (snippet): |
| 59 function enableCheckbox(checked) { | 71 function enableCheckbox(checked) { |
| 60 var elm = document.getElementById('checkbox'); | 72 var elm = document.getElementById('checkbox'); |
| 61 elm.checked = checked; | 73 elm.checked = checked; |
| 62 }</pre> | 74 }</pre> |
| OLD | NEW |