Skip to content

Commit 05e2140

Browse files
authored
jQuery.globalEval: Document the nonce option
Fixes jquery#1123 Closes jquery#1131
1 parent 51f3979 commit 05e2140

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

entries/jQuery.globalEval.xml

+24-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
<desc>The JavaScript code to execute.</desc>
88
</argument>
99
</signature>
10+
<signature>
11+
<added>3.4.0</added>
12+
<argument name="code" type="String">
13+
<desc>The JavaScript code to execute.</desc>
14+
</argument>
15+
<argument name="options" type="PlainObject" optional="true">
16+
<property name="nonce" type="string">
17+
<desc>The nonce attribute passed to the executed script.</desc>
18+
</property>
19+
</argument>
20+
</signature>
1021
<desc>Execute some JavaScript code globally.</desc>
1122
<longdesc>
1223
<p>This method behaves differently from using a normal JavaScript <code>eval()</code> in that it's executed within the global context (which is important for loading external scripts dynamically).</p>
@@ -15,7 +26,19 @@
1526
<desc>Execute a script in the global context.</desc>
1627
<code><![CDATA[
1728
function test() {
18-
jQuery.globalEval( "var newVar = true;" )
29+
jQuery.globalEval( "var newVar = true;" );
30+
}
31+
test();
32+
// newVar === true
33+
]]></code>
34+
</example>
35+
<example>
36+
<desc>Execute a script with a nonce value on a site with Content Security Policy enabled.</desc>
37+
<code><![CDATA[
38+
function test() {
39+
jQuery.globalEval( "var newVar = true;", {
40+
nonce: "nonce-2726c7f26c"
41+
} );
1942
}
2043
test();
2144
// newVar === true

0 commit comments

Comments
 (0)