Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/common/extensions/docs/static/content_scripts.html

Issue 412008: Introduce a new 'all_frames' property to content scripts and (Closed)
Patch Set: responses to comments Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 <br><br> 121 <br><br>
122 122
123 In the case of <code>"document_idle"</code>, the browser chooses a time to i nject scripts between <code>"document_end"</code> and immediately after the <cod e><a href="http://www.whatwg.org/specs/web-apps/current-work/#handler-onload">wi ndow.onload</a></code> event fires. The exact moment of injection depends on how complex the document is and how long it is taking to load, and is optimized for page load speed. 123 In the case of <code>"document_idle"</code>, the browser chooses a time to i nject scripts between <code>"document_end"</code> and immediately after the <cod e><a href="http://www.whatwg.org/specs/web-apps/current-work/#handler-onload">wi ndow.onload</a></code> event fires. The exact moment of injection depends on how complex the document is and how long it is taking to load, and is optimized for page load speed.
124 124
125 <br><br> 125 <br><br>
126 126
127 <b>NOTE:</b> In <code>document_idle</code>, content scripts may not necessar ily receive the window.onload event, because they may run after it has 127 <b>NOTE:</b> In <code>document_idle</code>, content scripts may not necessar ily receive the window.onload event, because they may run after it has
128 already fired. In most cases, listening for the onload event is unnecessary for content scripts running at <code>document_idle</code> because they are guara nteed to run after the DOM is complete. If your script definitely needs to run a fter <code>window.onload</code> you can check if it has already fired by using t he <code><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-documen t-readystate">document.readyState</a></code> property.</td> 128 already fired. In most cases, listening for the onload event is unnecessary for content scripts running at <code>document_idle</code> because they are guara nteed to run after the DOM is complete. If your script definitely needs to run a fter <code>window.onload</code> you can check if it has already fired by using t he <code><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-documen t-readystate">document.readyState</a></code> property.</td>
129 </tr> 129 </tr>
130 <tr>
131 <td>all_frames</td>
132 <td>boolean</td>
133 <td><em>Optional.</em>
134 Controls whether the content script runs in all frames of the matching page, or only the top frame.
135 <br><br>
136 Defaults to <code>false</code>, meaning that only the top frame is matched.< /td>
137 </tr>
130 </table> 138 </table>
131 139
132 140
133 <h2 id="execution-environment">Execution environment</h2> 141 <h2 id="execution-environment">Execution environment</h2>
134 142
135 <p>Content scripts execute in a special environment called an <em>isolated world </em>. They have access to the DOM of the page they are injected into, but not t o any JavaScript variables or functions created by the page. It looks to each co ntent script as if there is no other JavaScript executing on the page it is runn ing on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts. 143 <p>Content scripts execute in a special environment called an <em>isolated world </em>. They have access to the DOM of the page they are injected into, but not t o any JavaScript variables or functions created by the page. It looks to each co ntent script as if there is no other JavaScript executing on the page it is runn ing on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts.
136 144
137 <p>For example, consider this simple page: 145 <p>For example, consider this simple page:
138 146
139 <pre>hello.html 147 <pre>hello.html
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 just like you would any other URL, 212 just like you would any other URL,
205 as the following code shows. 213 as the following code shows.
206 </p> 214 </p>
207 215
208 216
209 <pre> 217 <pre>
210 <em>//Code for displaying &lt;extensionDir>/images/myimage.png:</em> 218 <em>//Code for displaying &lt;extensionDir>/images/myimage.png:</em>
211 var imgURL = <b>chrome.extension.getURL("images/myimage.png")</b>; 219 var imgURL = <b>chrome.extension.getURL("images/myimage.png")</b>;
212 document.getElementById("someImage").src = imgURL; 220 document.getElementById("someImage").src = imgURL;
213 </pre> 221 </pre>
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/examples/api/messaging/timer/page.js ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698