I am new to Flutter and I would like to render a partial content from a website in my Flutter application. Imagine this as an example: I want to render the main content of this website: https://flutter.dev/. I could obtain this content by executing the javascript command: document.getElementsByClassName("container")[0] .
What do I have to do to display this content in an WebView inside my Flutter application?
Thank you
This answer demonstrates how to pass html content to a Webview plugin in Flutter.
In your case you dont need to read from a file as in that answer, just pass in the String that you obtain from whatever means you need to use.
The relevant part of that answers code for you is:
String fileText = await rootBundle.loadString('assets/help.html');
_controller.loadUrl( Uri.dataFromString(
fileText,
mimeType: 'text/html',
encoding: Encoding.getByName('utf-8')
).toString());
where in your case the fileText String is the html content that you got from somewhere.
Related
I want to get the HTML content of an epub file by page. I tried epubx package but it's not working correctly. Has anyone managed to get HTML of an epub by page?
Try this package epub_parser
You can fetch html like the following
// Enumerating chapters
epubBook.Chapters.forEach((EpubChapter chapter) {
// HTML content of current chapter
String chapterHtmlContent = chapter.HtmlContent;
});
I use "webview_flutter: ^1.0.7" plugin in my flutter app to open a webview but I have a problem when a website launch a video after a click anywhere on the screen an it's open in fullscreen. How to disable it without disable javascript ? I want to play the video but not in fullscreen
I can't use "AutoMediaPlaybackPolicy" because there is an action
One way would be to update html file:
String hmtlCode = (await http.get(initialUrl)).body;
# edit this code (either append to string, or find and replace)
https://itqna.net/questions/80033/how-disable-full-screen-html5-video-any-browser (html example how to disable full screen)
and then feed this html to webview
String hmtlCode = ....;
String url = Uri.dataFromString(hmtlCode, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString();
WebView(
initialUrl: url,
...
I have an html page with image. The location of the image and imagename , has been given in the database table. How can I display the image by giving the image path and name from the database table using jQuery in visual studio code. Anybody can help me ?
So after getting the image src (image location and name) E.g. example.com/images/image.jpg you can then use .Append or .HTML to add the image element with that source.
If you were using AJAX to get the image source, then on the success function you can do
var imageSource = data; //data from the ajax call
$('body').append(`<img src="${imageSource}">`);
Or if you have the image already on the page, you can edit the source.
$("#imageID").attr("src", imageSource);
Your question was not very clear so I may have misunderstood your requirements.
I am using 'SwiftSoup' SDK to parse HTML content from UIWebView. I want the image size and resolution for each and every image fetched from HTML content. How to get the image size and resolution as soon as an image is loaded and from HTML content received from SwiftSoup?
Assuming you know when all images from the HTML are loaded, here's a javascript code that can be used to grab a list of sizes for all images:
let script = "JSON.stringify([].slice.call(document.getElementsByTagName('img')).map(function(img) { return {url: img.src, width: img.clientWidth, height: img.clientHeight} }))"
Executing this javascript via stringByEvaluatingJavaScript(from:) should give you a JSON that you can parse to obtain the desired info.
For example the output for this page is
[{"url":"https://i.stack.imgur.com/rQQMq.png?s=48&g=1","width":24,"height":24},{"url":"https://www.gravatar.com/avatar/46be6ae9d14855f5ab1aaf1d510ab8bc?s=32&d=identicon&r=PG&f=1","width":32,"height":32},{"url":"https://clc.stackoverflow.com/impression.gif?an=49ocs77evOWqh-6LVv8gJiaWI_07xL9f6GBcyDt7dl3NWtNsxo9-twOOBzKwMPRsYGBosGdkZGCRZuqawDHjMeecj4L_WRhSDiyObbJ82JRhP5vp7j6Og2e4ru0W9mRhmNs0gbnc8pVcsT0jc2Z-sTTTwxaOliucyy4LsrAwFLRcfRVt-e6KDEjTco4LjVyda4XkgZqaJcJzLa9Oj4RoMrJk4eJgYpBgYGDg4o1ij5VnYhAHsvk4o9gSmZgYRIBsfmYbtrvCTAxiIHH2ALapwv3t9i1z_NRrAA&md=291","width":0,"height":0}]
I'd recommend though to switch to WKWebView since it's recommended also by Apple, and because stringByEvaluatingJavaScript(from:) is blocking (WKWebView provides an async version of this function, and one that also will do the parsing for you, so you can remove the JSON.stringify() call from the script).
I am stucked on filepicker.io API from long days that how do i add style/css through javascript in ink filepicker.
I have also idea about i can add style to my ink filepicker from my account also but i have two filepicker.io on my same page i just want to change style for only one dialog so is there any way to do it.
filepicker.pick({ mimetype: "image/*" }, function (InkBlob) {
json = InkBlob;
var InkbolobFilename = json.filename;
var InkbolobUrl = json.url;
});
This my code snap so please help me out where i can add my css url.