-
Notifications
You must be signed in to change notification settings - Fork 23k
Fix content issues #41236
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
Fix content issues #41236
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -372,6 +372,7 @@ McLellan | |
| McNally | ||
| McVerry | ||
| Megalosaurus | ||
| Menard | ||
| Mercure | ||
| Merkle | ||
| mfuji | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,7 @@ browser-compat: api.HTMLScriptElement.text | |
| > See [Security considerations](#security_considerations) for more information. | ||
|
|
||
| The **`text`** property of the {{domxref("HTMLScriptElement")}} interface represents the inline text content of the script element. | ||
| It acts the same way as the {{domxref("HTMLScriptElement.textContent","textContent")}} property. | ||
|
|
||
| It reflects the `text` attribute of the {{HTMLElement("script")}} element. | ||
| It acts the same way as the {{domxref("Node.textContent","textContent")}} property. | ||
|
|
||
| ## Value | ||
|
|
||
|
|
@@ -37,10 +35,10 @@ Note that if the {{domxref('HTMLScriptElement/src','src')}} property is set the | |
|
|
||
| ### `text` vs `textContent` vs `innerText` | ||
|
|
||
| The `text` and {{domxref("HTMLScriptElement.textContent", "textContent")}} properties of `HTMLScriptElement` are equivalent: both can be set with a string or a `TrustedScript` type and both return a string representing the content of the script element. | ||
| The `text` and {{domxref("Node.textContent", "textContent")}} properties of `HTMLScriptElement` are equivalent: both can be set with a string or a `TrustedScript` type and both return a string representing the content of the script element. | ||
|
||
| The main difference is that {{domxref("Node.textContent", "textContent")}} is also defined on {{domxref("Node")}} and can be used with other elements to set their content with a string. | ||
|
|
||
| {{domxref("HTMLScriptElement.innerText", "innerText")}} will generally set and execute the text in the same way as the other methods, but may return a slightly different value. | ||
| {{domxref("HTMLElement.innerText", "innerText")}} will generally set and execute the text in the same way as the other methods, but may return a slightly different value. | ||
| The reason for this is that this property is designed for getting the rendered text of a string of HTML markup. | ||
| When setting the value the text is treated as a text node, which normalizes the string as if it were visible text (collapsing spaces and converting `\n` to line breaks). | ||
| This does not change the execution of the text, but it does alter the text that is stored and returned. | ||
|
|
@@ -81,12 +79,12 @@ For the purpose of this example we'll allow just exactly the script that we need | |
|
|
||
| ```js | ||
| const policy = trustedTypes.createPolicy("inline-script-policy", { | ||
| createScript: (input) => { | ||
| createScript(input) { | ||
| // Here specify what scripts are safe to allow | ||
| if (input === "const num = 10;\nconsole.log(num)") { | ||
| return input; // allow this exact script | ||
| } | ||
| throw new TypeError("Untrusted script blocked: " + input); | ||
| throw new TypeError(`Untrusted script blocked: ${input}`); | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
@@ -123,7 +121,7 @@ Note that in this case we're not using the policy to create trusted scripts (for | |
|
|
||
| ```js | ||
| // Set the text property | ||
| let el.text = "const num = 10;\nconsole.log(num)"; | ||
| el.text = "const num = 10;\nconsole.log(num)"; | ||
| console.log(el.text); // Output: "const num = 10;\nconsole.log(num);" | ||
| console.log(el.textContent); // Output: "const num = 10;\nconsole.log(num);" | ||
|
|
||
|
|
@@ -143,5 +141,5 @@ console.log(el.textContent); // Output: "console.log(10);" | |
|
|
||
| ## See also | ||
|
|
||
| - {{domxref("HTMLScriptElement.textContent")}} | ||
| - {{domxref("HTMLScriptElement.innerText")}} | ||
| - {{domxref("Node.textContent")}} | ||
| - {{domxref("HTMLElement.innerText")}} | ||
Uh oh!
There was an error while loading. Please reload this page.