Hi wzou,
Please try the new example code below. I have correct it to match your requirement. it will work with IE11 too.
1. create_a_custom_dialog.aspx code
- <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
- <%@ Page language="c#"%>
- <html>
- <head>
- <title>ASP.NET WYSIWYG Editor - How to create a custom button which displays a dialog?</title>
-
- <script language="JavaScript" type="text/javascript">
- function ShowMyDialog(button)
- {
-
- var editor=CuteEditor_GetEditor(button);
-
-
- var newwin=editor.ShowDialog(null,"My_Custom_Text.html?_rand="+new Date().getTime()
- ,editor,"dialogWidth:400px;dialogHeight:240px");
- }
- </script>
-
- <style>
- body {
- text-align: center;
- margin-top:20px
- }
- .demo {
- text-align: left;
- width: 800px;
- padding: 30px 30px 50px 30px;
- font-family:Segoe UI, Arial,Verdana,Helvetica,sans-serif;
- font-size: 100%;
- margin: 0 auto;
- }
- </style>
- </head>
- <body>
- <form runat="server" id="Form1">
- <div class="demo">
- <h3>
- How to create a custom button which displays a dialog?</h3>
- <p>
- In this example, first we get the location of Italic button. Then we add a custom
- dialog after it.</p>
- <CE:Editor id="Editor1" ThemeType="OfficeXP" AutoConfigure="Minimal" runat="server" />
- </div>
- </form>
- </body>
- </html>
- <script runat="server">
- private void Page_Load(object sender, System.EventArgs e)
- {
-
-
-
- int pos=Editor1.ToolControls.IndexOf("Italic")+1;
-
-
- WebControl ctrl=Editor1.CreateCommandButton("MyButton","text.gif","Insert My Custom Text");
-
- ctrl.Attributes["onclick"]="ShowMyDialog(this)";
-
-
- Editor1.InsertToolControl(pos,"MyButton",ctrl);
- }
- </script>
2. My_Custom_Text.html code
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <title>Insert Text</title>
- </head>
- <body bgcolor="#d4d0c8">
- <div align="center" style="padding:8px">
- <textarea rows="6" cols="40" id="ta" NAME="ta">Type content here</textarea>
- <br>
- <button onclick="button_click()" ID="Button1">Insert It</button>
- <button onclick="window.top.close();" ID="Button2">Close</button>
- </div>
- </body>
- <script>
- function button_click()
- {
- var editor=Window_GetDialogArguments(window);
- var ta=document.getElementById("ta");
- editor.FocusDocument();
- editor.PasteHTML(ta.value);
- }
- //Window_GetDialogArguments.js
- function Window_GetDialogArguments(win)
- {
- var top=win.top;
- try
- {
- var opener=top.opener;
- if(opener&&opener.document._dialog_arguments)
- return opener.document._dialog_arguments;
- }
- catch(x)
- {
- }
-
- if(top.document._dialog_arguments)
- return top.document._dialog_arguments;
- if(top.dialogArguments)
- return top.dialogArguments;
- return top.document._dialog_arguments;
- }
- window.onload=function()
- {
- var editor=Window_GetDialogArguments(window);
- var ta=document.getElementById("ta");
- ta.value= getSelectedHTML(editor);
-
- }
- function getSelectedHTML(editor)
- {
- var rng=null,html="";
-
- // get the active editor document
- var editdoc = editor.GetDocument();
-
- // get the active editor window
- var editwin = editor.GetWindow();
- if (document.selection && document.selection.createRange)
- {
- rng=editdoc.selection.createRange();
- if( rng.htmlText )
- {
- html=rng.htmlText;
- }
- else if(rng.length >= 1)
- {
- html=rng.item(0).outerHTML;
- }
- }
- else if (window.getSelection)
- {
- rng=editwin.getSelection();
-
- if (rng.rangeCount > 0 && window.XMLSerializer)
- {
- html=rng.getRangeAt(0);
- }
- }
- return html;
- }
- </script>
- </html>
Regards,
Ken