From Shaun Wilkinson, 1 Month ago, written in HTML5.
Embed
  1. function openEditWindow() {
  2.     //set tinymce options
  3.     var tinymcesource = '"https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=*APIKEY*"'
  4.     var tinymcepluginlist = '"advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code fullscreen insertdatetime media table contextmenu paste"';
  5.     var tinymcetoolbar = '"undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image preview"';
  6.    
  7.     //get the content of the e-mail description field
  8.     var emailBody = parent.Xrm.Page.getAttribute("description").getValue();
  9.    
  10.     //build the content of the editor popup window
  11.     var editContent = '<html>\n<head>';
  12.     editContent += '<title>TinyMCE E-mail Editor</title>\n';
  13.    
  14.     //this loads jquery from the google cdn. you can host it somewhere else.
  15.     editContent += '<scr'+'ipt src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></scr'+'ipt>';
  16.    
  17.     editContent += '<scr'+'ipt>';
  18.    
  19.     editContent += '$.ajaxSetup({cache: true});';
  20.        
  21.     //this function is used to update the crm e-mail body field and close the editor popup
  22.     editContent += 'function updateEmailForm() {\n';
  23.     editContent += 'window.opener.parent.Xrm.Page.getAttribute("description").setValue(tinymce.get("editbox").getContent());\n';
  24.     editContent += 'window.opener.parent.Xrm.Page.data.entity.attributes.get("description").controls.get(0).setFocus(a);\n';
  25.     editContent += 'this.window.close();\n';
  26.     editContent += '}';
  27.     editContent += '</scr'+'ipt>';
  28.     editContent += '</head>\n<body style="margin:0px 0px 0px 0px;" onload="initEditor();">';
  29.     editContent += '<scr'+'ipt>\n';
  30.  
  31.     //function to initialize the tinymce functionality
  32.     editContent += 'function initEditor() {';
  33.     editContent += 'if (typeof tinymce == "undefined") {';
  34.     editContent += '$("#editdiv").hide();';
  35.     editContent += '$.getScript('+tinymcesource+', function () {';
  36.     editContent += 'window.tinymce.dom.Event.domLoaded = true;';
  37.     editContent += 'tinymce.init({selector:"textarea",plugins: ['+tinymcepluginlist+'], toolbar:'+tinymcetoolbar+' })\n';
  38.     editContent += '$("#loadingdiv").hide();';
  39.     editContent += '$("#editdiv").show();';
  40.     editContent += '$("#editbuttondiv").show();';
  41.     editContent += '});';
  42.     editContent += '}';
  43.     editContent += '};';
  44.     editContent += '</scr'+'ipt>';
  45.    
  46.     editContent += '<div id="loadingdiv">Initializing editor . . . </div>';
  47.     editContent += '<div id="editdiv"><textarea id="editbox" style="width: 800px; height: 500px; ">'+emailBody+'</textarea>';
  48.     editContent += '<button style="height:42px;float:right;" onclick="updateEmailForm();">Update e-mail form and close</button></div>';
  49.     editContent += '</body></html>';
  50.    
  51.     //open the editor popup window
  52.     var editWindow = window.open("","editorwindow","height=588,width=800,scrollbars=yes");
  53.    
  54.     //write the editContent string to the editor popup
  55.     editWindow.document.write(editContent);
  56.    
  57.     //close the document stream
  58.     editWindow.document.close();
  59. }
  60. <body style="margin: 3px 0px 0px 5px; overflow-wrap: break-word;">
  61. <button onclick="openEditWindow();">Open TinyMCE Editor</button>
  62.  
  63. </body></html>