Skip to content

jQuery.globalEval: Document the nonce option #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion entries/jQuery.globalEval.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
<desc>The JavaScript code to execute.</desc>
</argument>
</signature>
<signature>
<added>3.4.0</added>
<argument name="code" type="String">
<desc>The JavaScript code to execute.</desc>
</argument>
<argument name="options" type="PlainObject" optional="true">
<property name="nonce" type="string">
<desc>The nonce attribute passed to the executed script.</desc>
</property>
</argument>
</signature>
<desc>Execute some JavaScript code globally.</desc>
<longdesc>
<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>
Expand All @@ -15,7 +26,19 @@
<desc>Execute a script in the global context.</desc>
<code><![CDATA[
function test() {
jQuery.globalEval( "var newVar = true;" )
jQuery.globalEval( "var newVar = true;" );
}
test();
// newVar === true
]]></code>
</example>
<example>
<desc>Execute a script with a nonce value on a site with Content Security Policy enabled.</desc>
<code><![CDATA[
function test() {
jQuery.globalEval( "var newVar = true;", {
nonce: "nonce-2726c7f26c"
} );
}
test();
// newVar === true
Expand Down