2016-10-04 6 views
0

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 없습니다.

답변

0

꽤 간단합니다. 디자인 모드를 true로 설정해야합니다.

document.designMode='on';