c# - ckeditor in WPF WebBrowser Control -


so having nightmare trying run ckeditor in wpf webbrowser control. custom built ckeditor our company using websites, throws error points nowhere.. line 0, yet works everywhere else, including ie. basic package, semi loads, throws undefined error , stay greyed out in loading phase. latest ck editor 4.7. i've tried using version 3.6 nothing happens @ all, ckeditor throws no error, doesnt load either ( works fine outside of wpf browser).

here basic html code inject wpfbrowser.

            webbrowser webbrowser = dependencyobject 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); 

other javascript such mathjax , on works fine, please ignore way build html, not relevant now.

this essay.js content

function replaceeditor() { ckeditor.replace('editor'); } window.onerror = function (message, url, linenumber) {     window.external.geterrors(message, url, linenumber); } 

catching errors doesnt returns same line 0 char 0 webbrowser throws errors . appreciated, i've read should working people made work before.

i guess know what's wrong, you're using navigatetostring, produces about:blank page. not going work ckeditor, same file://-based editor host page. need real http/https-based page, can simple referencing ckeditor cdn (a reliable amazon-hosted one):

<!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> 

below simple example loading ckeditor standard editor example wpf webbrowser control, works without issues me.

if can't have own dedicated online page host ckeditor, might need run in-app single-page web server serve via http://localhost. there're many examples out there on how (e.g. this one).

using microsoft.win32; using system; using system.diagnostics; using system.windows; using system.windows.controls;  namespace wpfwebeditor {     /// <summary>     /// interaction logic 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 required!");                 }                 int.tryparse(version.tostring().split('.')[0], out browserversion);             }              uint32 mode = 11000; // internet explorer 11. webpages containing standards-based !doctype directives displayed in ie11 standards mode. default value internet explorer 11.             switch (browserversion)             {                 case 7:                     mode = 7000; // webpages containing standards-based !doctype directives displayed in ie7 standards mode. default value applications hosting webbrowser control.                     break;                 case 8:                     mode = 8000; // webpages containing standards-based !doctype directives displayed in ie8 mode. default value internet explorer 8                     break;                 case 9:                     mode = 9000; // internet explorer 9. webpages containing standards-based !doctype directives displayed in ie9 mode. default value internet explorer 9.                     break;                 case 10:                     mode = 10000; // internet explorer 10. webpages containing standards-based !doctype directives displayed in ie10 mode. default value internet explorer 10.                     break;                 default:                     // use ie11 mode default                     break;             }              return mode;         }     } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -