How to Load HTML String in a Webview

How to load html string in a webview?

To load your data in WebView. Call loadData() method of WebView

wv.loadData(yourData, "text/html", "UTF-8");

You can check this example

http://developer.android.com/reference/android/webkit/WebView.html

[Edit 1]

You should add -- \ -- before -- " -- for example --> name=\"spanish press\"

below string worked for me

String webData =  "<!DOCTYPE html><head> <meta http-equiv=\"Content-Type\" " +
"content=\"text/html; charset=utf-8\"> <html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1250\">"+
"<meta name=\"spanish press\" content=\"spain, spanish newspaper, news,economy,politics,sports\"><title></title></head><body id=\"body\">"+
"<script src=\"http://www.myscript.com/a\"></script>şlkasşldkasşdksaşdkaşskdşk</body></html>";

unable to load html into webview from html string

Solved, I used

    webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);

How to load a HTML in String to WebView in Flutter

use this package flutter_html: ^1.0.0

import 'package:flutter_html/flutter_html.dart';

SingleChildScrollView(
child: Html(
data: "<div></div>", // Your Html code over here
padding: EdgeInsets.all(8.0),
));


Related Topics



Leave a reply



Submit