You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -94,6 +94,13 @@ Don't place a `<script>` tag in a component file because the `<script>` tag can'
94
94
95
95
The <xref:Microsoft.JSInterop.IJSRuntime> abstraction is asynchronous to allow for Blazor Server scenarios. If the app is a Blazor WebAssembly app and you want to invoke a JavaScript function synchronously, downcast to <xref:Microsoft.JSInterop.IJSInProcessRuntime> and call <xref:Microsoft.JSInterop.IJSInProcessRuntime.Invoke%2A> instead. We recommend that most JS interop libraries use the async APIs to ensure that the libraries are available in all scenarios.
96
96
97
+
::: moniker range=">= aspnetcore-5.0"
98
+
99
+
> [!NOTE]
100
+
> To enable JavaScript isolation in standard [JavaScript modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules), see the [Blazor JavaScript isolation and object references](#blazor-javascript-isolation-and-object-references) section.
101
+
102
+
::: moniker-end
103
+
97
104
The sample app includes a component to demonstrate JS interop. The component:
98
105
99
106
* Receives user input via a JavaScript prompt.
@@ -470,6 +477,43 @@ For more information, see the following issues:
470
477
*[Circular references are not supported, take two (dotnet/aspnetcore #20525)](https://github.com/dotnet/aspnetcore/issues/20525)
471
478
*[Proposal: Add mechanism to handle circular references when serializing (dotnet/runtime #30820)](https://github.com/dotnet/runtime/issues/30820)
472
479
480
+
::: moniker range=">= aspnetcore-5.0"
481
+
482
+
## Blazor JavaScript isolation and object references
483
+
484
+
Blazor enables JavaScript isolation in standard [JavaScript modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules). JavaScript isolation provides the following benefits:
485
+
486
+
* Imported JavaScript no longer pollutes the global namespace.
487
+
* Consumers of a library and components aren't required to import the related JavaScript.
488
+
489
+
For example, the following JavaScript module exports a JavaScript function for showing a browser prompt:
490
+
491
+
```javascript
492
+
exportfunctionshowPrompt(message) {
493
+
returnprompt(message, 'Type anything here');
494
+
}
495
+
```
496
+
497
+
Add the preceding JavaScript module to a .NET library as a static web asset (`wwwroot/exampleJsInterop.js`) and then import the module into the .NET code using the <xref:Microsoft.JSInterop.IJSRuntime> service. The service is injected as `jsRuntime` (not shown) for the following example:
The `import` identifier in the preceding example is a special identifier used specifically for importing a JavaScript module. Specify the module using its stable static web asset path: `_content/{LIBRARY NAME}/{PATH UNDER WWWROOT}`. The placeholder `{LIBRARY NAME}` is the library name. The placeholder `{PATH UNDER WWWROOT}` is the path to the script under `wwwroot`.
505
+
506
+
<xref:Microsoft.JSInterop.IJSRuntime> imports the module as a `JSObjectReference`, which represents a reference to a JavaScript object from .NET code. Use the `JSObjectReference` to invoke exported JavaScript functions from the module:
For more information, see [Annotating APIs as unsupported on specific platforms (dotnet/designs GitHub repository](https://github.com/dotnet/designs/blob/main/accepted/2020/platform-exclusion/platform-exclusion.md#build-configuration-for-platforms).
183
183
184
+
## Blazor JavaScript isolation and object references
185
+
186
+
Blazor enables JavaScript isolation in standard [JavaScript modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules). JavaScript isolation provides the following benefits:
187
+
188
+
* Imported JavaScript no longer pollutes the global namespace.
189
+
* Consumers of the library and components aren't required to manually import the related JavaScript.
190
+
191
+
For more information, see <xref:blazor/call-javascript-from-dotnet#blazor-javascript-isolation-and-object-references>.
0 commit comments