3 <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.
5 <h2 id=
"step_1">Step
1: Declare your options page in the manifest
</h2>
7 <pre data-filename=
"manifest.json">
9 "name":
"My extension",
11 <b>"options_page":
"options.html"</b>,
17 <h2 id=
"step_2">Step
2: Write your options page
</h2>
19 Here is an example options page:
21 <pre data-filename=
"options.html">
23 <head
><title
>My Test Extension Options
</title
></head
>
28 <select
id=
"color">
29 <option
value=
"red">red
</option
>
30 <option
value=
"green">green
</option
>
31 <option
value=
"blue">blue
</option
>
32 <option
value=
"yellow">yellow
</option
>
36 <div
id=
"status"></div
>
37 <button
id=
"save">Save
</button
>
40 <script
src=
"options.js"></script
>
45 <pre data-filename=
"options.js">
46 // Saves options to localStorage.
47 function save_options() {
48 var select = document.getElementById(
"color");
49 var color = select.children[select.selectedIndex].value;
50 localStorage[
"favorite_color"] = color;
52 // Update status to let user know options were saved.
53 var status = document.getElementById(
"status");
54 status.innerHTML =
"Options Saved.";
55 setTimeout(function() {
56 status.innerHTML =
"";
60 // Restores select box state to saved value from localStorage.
61 function restore_options() {
62 var favorite = localStorage[
"favorite_color"];
66 var select = document.getElementById(
"color");
67 for (var i =
0; i
< select.children.length; i++) {
68 var child = select.children[i];
69 if (child.value == favorite) {
70 child.selected =
"true";
75 document.addEventListener('DOMContentLoaded', restore_options);
76 document.querySelector('#save').addEventListener('click', save_options);
79 <h2 id=
"important_notes">Important notes
</h2>
81 <li>We plan on providing some default css styles to encourage a consistent look across different extensions' options pages. You can star
<a href=
"http://crbug.com/25317">crbug.com/
25317</a> to be notified of updates.
</li>