Welcome Guest Search | Active Topics | Sign In | Register

How to set WebView full screen in C# Options
CaiHua
Posted: Friday, March 10, 2023 1:52:02 AM
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
eo_support
Posted: Friday, March 10, 2023 10:57:46 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
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!
CaiHua
Posted: Wednesday, March 15, 2023 5:36:58 AM
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.
eo_support
Posted: Wednesday, March 15, 2023 11:51:14 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
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.html

Thanks!
CaiHua
Posted: Wednesday, March 15, 2023 8:13:10 PM
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
-------------------------
eo_support
Posted: Thursday, March 16, 2023 2:39:08 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
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!
CaiHua
Posted: Friday, March 17, 2023 2:05:43 AM
Rank: Newbie
Groups: Member

Joined: 4/12/2017
Posts: 5
Perfect, it works.

Thanks very much!!!
eo_support
Posted: Friday, March 17, 2023 8:53:19 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Great. Thanks for confirming!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.