Re: Custom Dialog Box

  •  10-22-2007, 11:04 AM

    Re: Custom Dialog Box

    Adam,
       Thanks.
       I've modified my Dialog Box script.
       I'm not understanding why the var editor = Window_GetDialogArguments(window); portion of the script isn't recognized when I use rng = editor.selection.createRange();.
       The script generates a editor.selection is Null or not an object.
       I want to preserve the selected text if any has been selected, or use the .text property of the options collection for the selected option in a select.
       Here is the script:
     
      <script language="javascript" type="text/javascript">
       var editor = Window_GetDialogArguments(window);
       var selectedPage = document.getElementById('allPages');
       var selectedText = '';
       
       function button_click() {
        selectedText = getSelectedHTML();
        if(selectedText != '') {
         //do nothing
        }
        else {
         selectedText = selectedPage.options[selectedPage.selectedIndex].text;
        }
        editor.PasteHTML('<a href="http://cutesoft.net/websites/index.asp?dpt=<%=Request.QueryString("dpt")%>&pageID='+selectedPage.options[selectedPage.selectedIndex].value+'">'+selectedText+'</a>');
        window.close();
       }
       
       function Window_GetDialogArguments(win) {
        var top = win.top;
        var opener = top.opener;
        
        if(top.dialogArguments) {
         return top.dialogArguments;
        }
        
        if(opener == null) {
         return top.document._dialog_arguments;
        }
        
        return opener.document._dialog_arguments;
       }
       
       function getSelectedHTML() {
        var rng = null
        var html = '';
     
        if(document.selection && document.selection.createRange) {
         rng = editor.selection.createRange();
         html = rng.htmlText || "";
        }
        else if(window.getSelection) {
         rng = editor.getSelection();
     
         if(rng.rangeCount > 0 && window.XMLSerializer) {
          rng = rng.getRangeAt(0);
          html = new XMLSerializer().serializeToString(rng.cloneContents());
         }
        }
        
           return html;
         }
      </script>

    Work Hard! Play Harder!!
View Complete Thread