|
Rank: Newbie Groups: Member
Joined: 4/12/2017 Posts: 5
|
How to set WebView full screen in C#, example code: ============================================================= private void Form1_Load(object sender, EventArgs e) { //inject js function webControl1.WebView.JSInitCode = @"function fn_Fullscreen() {alert(1);document.documentElement.requestFullscreen()};"; webControl1.WebView.LoadUrl("https://www.bing.com"); }
private void btnFullScreen_Click(object sender, EventArgs e) { if (!webControl1.WebView.IsFullscreenMode) { //Fullscreen webControl1.WebView.EvalScript("fn_Fullscreen()", true); //webControl1.WebView.InvokeFunction("fn_Fullscreen"); } }
========================================================
alert is shown,but full screen does not work.
Looking forward to your reply
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, Instead of setting JSInitCode to:
Code: JavaScript
function fn_Fullscreen() { ... }
Please try to set it to:
Code: JavaScript
window["fn_Fullscreen"] = function() { .... }
The reason is JSInitCode is run in a local scope. So the first version would define fn_Fullscreen in a local scope that is not accessible to code outside of that scope. The second version would define the function in the global scope. Please let us know if this works for you. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/12/2017 Posts: 5
|
still not working.An exception prompt is printed to the console:
a.html:10 Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture. window.fn_Fullscreen @ a.html:10 (anonymous) @ VM15:1 a.html:10 Uncaught (in promise) TypeError: fullscreen error at window.fn_Fullscreen (a.html:10:73) at <anonymous>:1:1
If I click the webview first , then it works. so how do I simulate a user clicking on the webview? I tried set webview's focus,but it does not work.
I want add a “Fullscreen” button in the top toolbar. if the user didn't click webview first,the “Fullscreen” button does not work.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, There is no way to do that in the current build. However in our next build you will be able to set this property to true in order to allow it: https://www.essentialobjects.com/doc/eo.webengine.engineoptions.bypassusergesturecheck.htmlThanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/12/2017 Posts: 5
|
ok,thanks. I used code like below in current version (23.1.25.0),but it also does not work. so when will the next version be released and what is the version number? I am looking forward to it.
EO.WebEngine.Engine.Default.Options.BypassUserGestureCheck = true -------------------------
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
We have posted build 23.1.45. This build would allow you to set BypassUserGestureCheck to true to allow you to switch to full screen through JavaScript. You can download the new build from our download page. Please take a look and let us know how it goes.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/12/2017 Posts: 5
|
Perfect, it works.
Thanks very much!!!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Great. Thanks for confirming!
|
|