【问题标题】:Not able to make the Webview editable无法使 Webview 可编辑
【发布时间】:2017-02-12 06:42:16
【问题描述】:

我正在尝试让 webview 控件进入可编辑模式(适用于 UWP)。这是我注入 js 的代码:

private const string EditableParameter = "~editable~";
private const string SetBodyEditableScript = @"
        try
        {  
            document.body.contentEditable = '" + EditableParameter + @"';
        }
        catch(e)
        {

        }";

public MainPage()
{
    this.InitializeComponent();
    MakeWebviewEditable();
}

private const string EventNotificationFormat = @"window.external.notify('{0}');";
private async void MakeWebviewEditable()
{
    await InjectJavaScriptAsync(SetBodyEditableScript.Replace(EditableParameter, "true"));
}

private async Task InjectJavaScriptAsync(string jscript)
        {
            await WebView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {                        
                        string result = await WebView.InvokeScriptAsync("eval", new string[] { jscript });
                }
                catch (Exception ex)
                {

                }
            });
        }

但它不起作用,webview 控件仍然不是editable

【问题讨论】:

    标签: javascript webview uwp contenteditable


    【解决方案1】:

    结果很简单。只需将设计模式设置为 true:

    document.designMode='on';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 2022-11-25
      相关资源
      最近更新 更多