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

Unified Diff: chrome/common/extensions/docs/static/contentSecurityPolicy.html

Issue 10832110: Docs: Clarifying the CSP-friendly replacement for <body onload="XXX">. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebuilt. Created 8 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/server2/templates/articles/contentSecurityPolicy.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/static/contentSecurityPolicy.html
diff --git a/chrome/common/extensions/docs/static/contentSecurityPolicy.html b/chrome/common/extensions/docs/static/contentSecurityPolicy.html
index e70b58fbb3e36e72e476f7c4c8bcd4c48d5f6a02..edd84b4c6171cc5bf6868756debd11f6da0c4fb9 100644
--- a/chrome/common/extensions/docs/static/contentSecurityPolicy.html
+++ b/chrome/common/extensions/docs/static/contentSecurityPolicy.html
@@ -93,9 +93,13 @@
function clickHandler(element) {
setTimeout(<strong>"awesome(); totallyAwesome()"</strong>, 1000);
}
+
+ function main() {
+ // Initialization work goes here.
+ }
&lt;/script&gt;
&lt;/head&gt;
- &lt;body&gt;
+ &lt;body onload="main();"&gt;
&lt;button <strong>onclick="clickHandler(this)"</strong>&gt;
Click for awesomeness!
&lt;/button&gt;
@@ -113,8 +117,13 @@
JavaScript file (<code>popup.js</code> would be a good target).
</li>
<li>
- The inline event handler definition must be rewritten in terms of
- <code>addEventListener</code> and extracted into <code>popup.js</code>.
+ <p>The inline event handler definitions must be rewritten in terms of
+ <code>addEventListener</code> and extracted into <code>popup.js</code>.</p>
+ <p>If you're currently kicking off your program's execution via code like
+ <code>&lt;body onload="main();"&gt;</code>, consider replacing it by hooking
+ into the document's <code>DOMContentLoaded</code> event, or the window's
+ <code>load</code> event, depending on your needs. Below we'll use the
+ former, as it generally triggers more quickly.</p>
</li>
<li>
The <code>setTimeout</code> call will need to be rewritten to avoid
@@ -138,25 +147,28 @@ function totallyAwesome() {
// do something TOTALLY awesome!
}
-<strong>
-function awesomeTask() {
+<strong>function awesomeTask() {
awesome();
totallyAwesome();
-}
-</strong>
+}</strong>
function clickHandler(e) {
setTimeout(<strong>awesomeTask</strong>, 1000);
}
+function main() {
+ // Initialization work goes here.
+}
+
// Add event listeners once the DOM has fully loaded by listening for the
// `DOMContentLoaded` event on the document, and adding your listeners to
// specific elements when it triggers.
-document.addEventListener('DOMContentLoaded', function () {
+<strong>document.addEventListener('DOMContentLoaded', function () {</strong>
document.querySelector('button').addEventListener('click', clickHandler);
+ main();
});
-
-popup.html:
+</pre>
+<pre>popup.html:
===========
&lt;!doctype html&gt;
« no previous file with comments | « chrome/common/extensions/docs/server2/templates/articles/contentSecurityPolicy.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698