OLD | NEW |
1 <div id="pageData-title" class="pageData">Content Scripts</div> | 1 <div id="pageData-title" class="pageData">Content Scripts</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 Content Scripts are JavaScript files that run in the context of web pages. | 5 Content scripts are JavaScript files that run in the context of web pages. |
6 By using the standard | 6 By using the standard |
7 <a href="http://www.w3.org/TR/DOM-Level-2-HTML/">Document | 7 <a href="http://www.w3.org/TR/DOM-Level-2-HTML/">Document |
8 Object Model</a> (DOM), | 8 Object Model</a> (DOM), |
9 they can read details of the web pages the browser visits, | 9 they can read details of the web pages the browser visits, |
10 or make changes to them. | 10 or make changes to them. |
11 </p> | 11 </p> |
12 | 12 |
13 <p> | 13 <p> |
14 Here are some examples of what content scripts can do: | 14 Here are some examples of what content scripts can do: |
15 </p> | 15 </p> |
16 | 16 |
17 <ul> | 17 <ul> |
18 <li>Find unlinked URLs in web pages and convert them into hyperlinks | 18 <li>Find unlinked URLs in web pages and convert them into hyperlinks |
19 <li>Increase the font size to make text more legible | 19 <li>Increase the font size to make text more legible |
20 <li>Find and process <a href="http://microformats.org/">microformat</a> data i
n the DOM | 20 <li>Find and process <a href="http://microformats.org/">microformat</a> data i
n the DOM |
21 </ul> | 21 </ul> |
22 | 22 |
23 <p> | 23 <p> |
24 However, content scripts have some limitations. | 24 However, content scripts have some limitations. |
25 They <b>cannot use</b>: | 25 They <b>cannot</b>: |
26 </p> | 26 </p> |
27 | 27 |
28 <ul> | 28 <ul> |
29 <li> | 29 <li> |
30 chrome.* APIs | 30 Use chrome.* APIs |
31 (except for parts of | 31 (except for parts of |
32 <a href="extension.html"><code>chrome.extension</code></a>) | 32 <a href="extension.html"><code>chrome.extension</code></a>) |
33 </li> | 33 </li> |
34 <li> | 34 <li> |
35 variables or functions defined by their extension's pages | 35 Use variables or functions defined by their extension's pages |
36 </li> | 36 </li> |
37 <li> | 37 <li> |
38 variables or functions defined by web pages or by other content scripts | 38 Use variables or functions defined by web pages or by other content scripts |
| 39 </li> |
| 40 <li> |
| 41 Make cross-site XMLHttpRequests |
39 </li> | 42 </li> |
40 </ul> | 43 </ul> |
41 | 44 |
42 <p> | 45 <p> |
43 These limitations aren't as bad as they sound. | 46 These limitations aren't as bad as they sound. |
44 Content scripts can <em>indirectly</em> use the chrome.* APIs, | 47 Content scripts can <em>indirectly</em> use the chrome.* APIs, |
45 get access to extension data, | 48 get access to extension data, |
46 and request extension actions | 49 and request extension actions |
47 by exchanging <a href="#messaging">messages</a> | 50 by exchanging <a href="#messaging">messages</a> |
48 with their parent extension. | 51 with their parent extension. |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 just like you would any other URL, | 245 just like you would any other URL, |
243 as the following code shows. | 246 as the following code shows. |
244 </p> | 247 </p> |
245 | 248 |
246 | 249 |
247 <pre> | 250 <pre> |
248 <em>//Code for displaying <extensionDir>/images/myimage.png:</em> | 251 <em>//Code for displaying <extensionDir>/images/myimage.png:</em> |
249 var imgURL = <b>chrome.extension.getURL("images/myimage.png")</b>; | 252 var imgURL = <b>chrome.extension.getURL("images/myimage.png")</b>; |
250 document.getElementById("someImage").src = imgURL; | 253 document.getElementById("someImage").src = imgURL; |
251 </pre> | 254 </pre> |
OLD | NEW |