4 There is a new way to write your options pages, starting from Chrome
40.
5 <a href=
"optionsV2">Learn more
</a>, and try it out!
8 <p>To allow users to customize the behavior of your extension, you may wish to provide an options page. If you do, a link to it will be provided from the extensions management page at chrome://extensions. Clicking the Options link opens a new tab pointing at your options page.
</p>
10 <p>Use the $(ref:storage.sync) API to persist these preferences. These values will then become accessible in any script within your extension, on all your user's devices.
</p>
12 <h2 id=
"step_1">Step
1: Declare your options page in the manifest
</h2>
14 <pre data-filename=
"manifest.json">
16 "name":
"My extension",
18 <b>"options_page":
"options.html"</b>,
23 <h2 id=
"step_2">Step
2: Write your options page
</h2>
25 Here is an example options page:
27 <pre data-filename=
"options.html">
30 <head
><title
>My Test Extension Options
</title
></head
>
34 <select
id=
"color">
35 <option
value=
"red">red
</option
>
36 <option
value=
"green">green
</option
>
37 <option
value=
"blue">blue
</option
>
38 <option
value=
"yellow">yellow
</option
>
42 <input
type=
"checkbox" id=
"like">
46 <div
id=
"status"></div
>
47 <button
id=
"save">Save
</button
>
49 <script
src=
"options.js"></script
>
54 <pre data-filename=
"options.js">
55 // Saves options to chrome.storage
56 function save_options() {
57 var color = document.getElementById('color').value;
58 var likesColor = document.getElementById('like').checked;
59 chrome.storage.sync.set({
61 likesColor: likesColor
63 // Update status to let user know options were saved.
64 var status = document.getElementById('status');
65 status.textContent = 'Options saved.';
66 setTimeout(function() {
67 status.textContent = '';
72 // Restores select box and checkbox state using the preferences
73 // stored in chrome.storage.
74 function restore_options() {
75 // Use default value color = 'red' and likesColor = true.
76 chrome.storage.sync.get({
80 document.getElementById('color').value = items.favoriteColor;
81 document.getElementById('like').checked = items.likesColor;
84 document.addEventListener('DOMContentLoaded', restore_options);
85 document.getElementById('save').addEventListener('click',