|
Rank: Newbie Groups: Member
Joined: 9/21/2021 Posts: 4
|
Our app calls WebView.InvokeFunction(name, arg) to call into the web script. The call is done from a hotkey invoked Command which is part of the CommandBindings of the window. It appears as though there have been some changes since the 21.1.85 version that causes this approach to lock up the application. My guess is this might be due to the change that also forwarded the hot keys up to the application automatically - in 21.1.85 if the WebView had focus our app wouldn't receive hot key events. This change is appreciated! I've determined that using WebView.QueueScriptCall appears to fix the issue. The problem is that the argument we pass into InvokeFunction is code itself and just can't be placed into the call directly with "func('<arg_val>'). From the documentation I don't see a way to pass the function and argument separately using QueueScriptCall. Am I missing it or is there another way to accomplish this? Here is a simple program to show the issue
Code:
<Window x:Class="WpfApp6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:eo="http://schemas.essentialobjects.com/wpf/" xmlns:local="clr-namespace:WpfApp6" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Window.CommandBindings> <CommandBinding Command="local:MainWindow.TestCommand" Executed="CommandBinding_OnExecuted"/> </Window.CommandBindings> <eo:WebControl Grid.Row="1" x:Name="eob"/> </Window>
Code:
using EO.WebBrowser; using System.Windows; using System.Windows.Input;
namespace WpfApp6 { public partial class MainWindow : Window { public static RoutedUICommand TestCommand = new RoutedUICommand( "Test", "Test", typeof(MainWindow), new InputGestureCollection( new KeyGesture[] { new KeyGesture(Key.T, ModifierKeys.Control, "Ctrl+T") }));
public MainWindow() { InitializeComponent(); eob.WebView = new WebView { Url = "file:///.../index.html" }; } private void CommandBinding_OnExecuted(object sender, ExecutedRoutedEventArgs e) { eob.WebView.QueueScriptCall("hey('test')"); // this will fail //eob.WebView.InvokeFunction("hey", "this is a test"); } } }
Code:
<html> <script> function hey(text) { alert(text); } </script> <textarea id="txt" rows="4" cols="50"> At w3schools.com you will learn how to make a website. They offer free tutorials in all web development technologies. </textarea> <button onclick="hey('sts')">hasdf</button> </html>
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
Sorry about the delay --- I am not sure what you meant by "The problem is that the argument we pass into InvokeFunction is code itself and just can't be placed into the call directly". The code you posted does use QueueScriptCall to call hey('test') and it should work right?
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/21/2021 Posts: 4
|
Yes, my sample code does work but it won't work for my actual use case. What I want to do is
Code: C#
string arg = Some long string that would be difficult to escape
eob.WebView.QueueScriptCall("hey", arg);
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
I see. In that case you can use QueueScriptCall and InvokeFunction together like this:
Code: C#
webView.QueueScriptCall(() =>
{
webView.InvokeFunction("alert", "hi");
});
Please let us know if this works for you. Thanks!
|
|