Skip to content

Commit f6c17c7

Browse files
committed
WebView (Android, .NET 10): document JavaScript enable/disable via PlatformConfiguration.AndroidSpecific.WebView APIs; note default enabled and EvaluateJavaScriptAsync caveat; update ms.date.
1 parent ad2360b commit f6c17c7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/user-interface/controls/webview.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "WebView"
33
description: "This article explains how to use the .NET MAUI WebView to display remote web pages, local HTML files, and HTML strings."
4-
ms.date: 04/15/2025
4+
ms.date: 08/19/2025
55
zone_pivot_groups: devices-platforms
66
---
77

@@ -234,6 +234,27 @@ When page navigation occurs in a <xref:Microsoft.Maui.Controls.WebView>, either
234234

235235
::: moniker range=">=net-maui-10.0"
236236

237+
## Enable or disable JavaScript on Android
238+
239+
On Android, JavaScript execution is enabled by default for <xref:Microsoft.Maui.Controls.WebView>. You can toggle this behavior at runtime using the Android-specific platform configuration APIs:
240+
241+
```csharp
242+
using Microsoft.Maui.Controls.PlatformConfiguration;
243+
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
244+
245+
// Disable JavaScript
246+
webView.On<Android>().SetJavaScriptEnabled(false);
247+
248+
// Re-enable JavaScript
249+
webView.On<Android>().SetJavaScriptEnabled(true);
250+
251+
// Query current state
252+
bool isEnabled = webView.On<Android>().IsJavaScriptEnabled();
253+
```
254+
255+
> [!NOTE]
256+
> Disabling JavaScript may break functionality on sites that rely on it. Additionally, calls to <xref:Microsoft.Maui.Controls.WebView.EvaluateJavaScriptAsync%2A> won't execute scripts while JavaScript is disabled.
257+
237258
## Play video full screen on Android
238259

239260
When videos are hosted in a <xref:Microsoft.Maui.Controls.WebView> on Android, they can be played fullscreen by including `allowfullscreen` in the `iframe`:

0 commit comments

Comments
 (0)