I am load website with Flutter webview. But I want replace HTML element when it load. For example:
<span class="name">Replace text</span>
How to do?
So, it depends what library you are using to load your webview.
I have had some good success using webview_flutter_plus (https://pub.dev/packages/webview_flutter_plus).
With this, you just need to wait for your html to load and inject some javascript to modify whatever html you want.
Like this:
Widget build(BuildContext context) {
return WebViewPlus(
initialUrl: myUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewPlusController webViewController) {
_webViewController = webViewController;
},
onPageFinished: (String url) {
_webViewController.evaluateJavascript('document.querySelector(".name").innerHTML = "new text";');
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With