2017-07-28 17 views
1

wpf webbrowserコントロールでckeditorを実行しようとしました。私たちの会社がウェブサイトに使用しているカスタマイズされたckeditorは、ライン0を指し示すエラーをスローしますが、IEを含む他のすべての場所で動作します。基本的なパッケージ、半負荷ですが、未定義のエラーをスローし、ローディングフェーズではグレー表示のままです。これは最新のckエディタ4.7にあります。 何も起こらないバージョン3.6を使用しようとしましたが、ckeditorはエラーをスローしませんが、どちらかをロードしません(wpfブラウザ外で正常に動作します)。WPF WebBrowserコントロールのckeditor

ここに、wpfbrowserに注入する基本的なhtmlコードをいくつか示します。このようMathJaxなど作品の罰金として

  WebBrowser webBrowser = dependencyObject as WebBrowser; 
     if (webBrowser != null) 
     { 
      var html = "<head>" + 

         "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />" + 
         "<meta charset=\"UTF-8\">" + 

         // $"<script type=\"text/javascript\" src=\"{ResourceDir}MathJax\\MathJax.js?config=MML_HTMLorMML,default\"></script>" + 
         $"<script type=\"text/javascript\" src=\"{ResourceDir}ckeditor\\ckeditor.js\"></script>" + 
         $"<script type=\"text/javascript\" src=\"{ResourceDir}JavaScript\\essay.js\"></script>" + 
         // $"<link rel=\"stylesheet\" type=\"text/css\" href=\"{ResourceDir}\\CSS\\main.css\">" + 

         "</head>" + 

         "<body>" + 
         "   <form>\r\n" + 
         "   <textarea name=\"editor\" id=\"editor\" rows=\"10\" cols=\"80\">\r\n" + 
            $"Hello World!" + /*{e.NewValue}*/ 
         "   </textarea>\r\n" + 
         "  </form>"+ 
         " <button onclick=\"ReplaceEditor()\">Click me</button> " + 
         "</body>"; 

      webBrowser.NavigateToString(html); 

他のJavaScript、私は今、関連する、HTMLを構築していない道を無視してください。

これは、ウェブブラウザは、すべてのエラーをスロー0文字0と同じ行を返すようにエラーが多くを助けるdoesntのキャッチessay.jsコンテンツ

function ReplaceEditor() { 
CKEDITOR.replace('editor'); 
} 
window.onerror = function (message, url, lineNumber) { 
    window.external.GetErrors(message, url, lineNumber); 
} 

です。私がそれを読んだことから、どんな助けにも感謝しています。

+0

ありました。 [this](https://stackoverflow.com/a/18333982/1768303)が役立つかどうかを確認してください。 – Noseratio

+0

悲しいことに、厄介なwpf webbrowserのための私の他の回避策が壊れてしまったので、元に戻す必要があり、外部からappとしてレジストリに書き込むことを好まない。 –

+0

私はCKEditor 4.5.xをそのようなホストで心配なしで使用することができました。 HKCUに書き込むので、管理者権限は必要ありません。しかし、後でCKEditorのバージョンについてはわかりません。 – Noseratio

答えて

1

私は何が間違っているのか分かりますが、NavigateToStringを使用しています。これはabout:blankページを生成しています。これは、file://ベースのエディタホストページと同じCKEditorでは動作しません。あなたは彼らのCDNからCKEditorバージョンを参照するような単純なことができhttp/httpsリアルベースのページを、(非常に信頼性の高い1アマゾンでホストされている)必要があります。

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title>CKEditor</title> 
     <script src="https://cdn.ckeditor.com/4.7.1/standard/ckeditor.js"></script> 
    </head> 
    <body> 
     <textarea name="editor1"></textarea> 
     <script> 
      CKEDITOR.replace('editor1'); 
     </script> 
    </body> 
</html> 
以下

は、WPF WebBrowserコントロールにCKEditor Standard Editor Exampleをロードする簡単な例でありますそれは私のために問題なく動作します。

CKEditorをホストする専用のオンラインページがない場合は、http://localhostでサービスするために、アプリ内の単一ページのWebサーバーを実行する必要があります。方法については、多くの例があります(例:this one)。

using Microsoft.Win32; 
using System; 
using System.Diagnostics; 
using System.Windows; 
using System.Windows.Controls; 

namespace WpfWebEditor 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     WebBrowser _webBrowser; 

     static MainWindow() 
     { 
      var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName); 
      SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode()); 
     } 

     public MainWindow() 
     { 
      InitializeComponent(); 
      this.Loaded += MainWindow_Loaded; 

      _webBrowser = new WebBrowser(); 
      this.Content = _webBrowser; 
     } 

     private void MainWindow_Loaded(object sender, RoutedEventArgs e) 
     { 
      _webBrowser.Navigate("https://nightly.ckeditor.com/standard/samples/"); 
     } 

     private static void SetBrowserFeatureControlKey(string feature, string appName, uint value) 
     { 
      using (var key = Registry.CurrentUser.CreateSubKey(
       String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature), 
       RegistryKeyPermissionCheck.ReadWriteSubTree)) 
      { 
       key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord); 
      } 
     } 

     private static UInt32 GetBrowserEmulationMode() 
     { 
      int browserVersion = 7; 
      using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer", 
       RegistryKeyPermissionCheck.ReadSubTree, 
       System.Security.AccessControl.RegistryRights.QueryValues)) 
      { 
       var version = ieKey.GetValue("svcVersion"); 
       if (null == version) 
       { 
        version = ieKey.GetValue("Version"); 
        if (null == version) 
         throw new ApplicationException("Microsoft Internet Explorer is required!"); 
       } 
       int.TryParse(version.ToString().Split('.')[0], out browserVersion); 
      } 

      UInt32 mode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode. Default value for Internet Explorer 11. 
      switch (browserVersion) 
      { 
       case 7: 
        mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control. 
        break; 
       case 8: 
        mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8 
        break; 
       case 9: 
        mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9. 
        break; 
       case 10: 
        mode = 10000; // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 mode. Default value for Internet Explorer 10. 
        break; 
       default: 
        // use IE11 mode by default 
        break; 
      } 

      return mode; 
     } 
    } 
} 
+1

これは実際にはうまくいきますが、ブラウザの機能を設定する必要はありません(ただし、これはどのように役立つか分かります)。ローカルhttpページをホストする必要はありません。それは私が答えを書くかどうか熟考しているか、あなたの投稿なしで私はそれを考えなかったとしてあなたを受け入れることができます。 –

+0

@AistisTaraskevicius、喜んでそれを助けました。私はそれを試したと確信しています。とにかく、詳細な回答を投稿して、他の人がそれから恩恵を受けることができるようにしてください。 – Noseratio

関連する問題