0

I am using WPF and have used the Microsoft.Toolkit.Wpf.UI.Controls.WebView control to host the webpage for a simple online game. The game has a button that makes the root content stretch to fullscreen (as the window).

This button is simply defined in the HTML as <div class="fullscreen" onclick="unityInstance.SetFullscreen(1)"></div>

I can open the console in a web browser and run unityInstance.SetFullscreen(1), but I want to do that within my webview. I've tried MainView.InvokeScript("eval", new[] { "unityInstance.SetFullscreen(1)" }); but that just throws an exception HRESULT: 0x80020101

Ignore the "fullscreen" part of the question -- I just want to run that command in the webview. Is that possible? Thanks.

1 Answer 1

1

I would recommend you to enable scripts and try to invoke your script this way:

MainView.IsScriptEnabled = true;
MainView.InvokeScript("eval", new string[] { "unityInstance.SetFullscreen(1);" });
Sign up to request clarification or add additional context in comments.

1 Comment

I set IsJavaScriptEnabled property to true and this worked perfectly as expected. I'm wondering how I didn't do that. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.