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,
...
Related
I just want to download an image from the URL instead of open it in a new tab. I already try some code, but it didn't work as I want
1. url_launcher
launch(my_url);
2. url_launcher_web
final launcher = UrlLauncherPlugin();
launcher.launch(my_url);
3. dio
final response = await Dio().download(my_url, './xx.html');
UPDATE
Please note that I don't want to open the file in a new tab or current tab, I just want to direct download the file (something like making a stream to download).
For flutter web to download any file you can take the help of HTML library which will treat it as simply an anchor tag with download option. Note this can download any file so better check for IMAGE URL'S as well.
import 'dart:html' as html;
void downloadImage(String url){
html.AnchorElement anchorElement = new html.AnchorElement(href: url);
anchorElement.download = url;
anchorElement.click();
}
I want to show my PDF and PPT files within the app without using any other app in Flutter.
Not from the local assets but from web Urls.
For PDF you can use this package: https://pub.dev/packages/advance_pdf_viewer
Example:
Load from URL
PDFDocument doc = await PDFDocument.fromURL(yourURL);
Container(
child: PDFViewer(document: doc)),
);
I have Test page that loads data from HTML for each question of the Test. Whenever I get video as a iFrame from the HTML, I parse it to data URI and then will display that video in a WebView. I use this same page for all the questions. When I click next question I used the following code to display new video in the same webview.
webviewController.loadUrl(newUrl)
This works completely fine until I have two or more videos in the same page. When there is two or more videos in the same page. The videos in the upcoming page shows the same previous video.
Below is code how I render my Video from html.
Widget renderVideo(dom.Element iframe) {
String initialUrl =
Uri.dataFromString(iframe, mimeType: 'text/html')
.toString();
if (testBloc.webViewController != null) {
testBloc.webViewController.loadUrl(initialUrl);
}
return Container(
width: 300,
height: 350,
child: WebView(
initialUrl: initialUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController controller) {
testBloc.webViewController = controller;
controller.loadUrl(initialUrl);
},
),
);
}
So everytime there is iframe this method will be called in a page. So when there is only one video in the page this will be called once. When there is two or more videos in the page, this is will be called two or more times creating as many as webviews. Whenever I encounter two or more videos in single page, the upcoming pages webview will display the same video that came in the multiple video page.
For example:
Page 1: It has one video. It will be displayed in the webview.
Page 2: If it has two or more video. It will be displayed in as many webviews.
Page 3: And then the page followed by the multi video page does not display its own video. Instead it
displays the video of the page 2. All the upcoming pages from here also display the video of the page 2.
I could not find why this is happening and how to resolve this. Can anyone guide me here.
I am sorry If I have not explained it properly or if I have elaborated it big. Maybe reading the example might make you understand the problem clearly.
Thanks in advance.
You might've need to wrap loadUrl() inside setState() to update the WebViewController's loadUrl. This should rebuild the WebView with the new URL.
setState((){
testBloc.webViewController.loadUrl(newUrl)
});
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.
I have a Swift application that opens a PDF file in webView with the function webView.load(request).
It perfectly works at debug time with the simulator, but when launched in the real device (an iPad) the PDF file is not shown.
The app does not set any error.
Any help is welcome
This might be so obvious question: Is your iPad connected to internet?
Then maybe it's because your link isn't and "https://...." but just an "http://" and maybe the webview won't open it because of that
The PDF file is located in the default documents folder.
Any loading to the webView is working, but not the loading of a PDF file.
The strange is that the same code works in the simulator.
For Swift 3 use this
let url = URL(fileURLWithPath: filePath)
let urlRequest = URLRequest(url: url)
webView?.loadRequest(urlRequest)