FreeTextBox

The no. 1 free ASP.NET HTML Editor.
Welcome to FreeTextBox Sign in | Join | Help
in Search

PasteMode - How to prevent pasting of formatted text

Last post 05-16-2008, 1:04 PM by lyfschaos. 6 replies.
Sort Posts: Previous Next
  •  12-06-2004, 2:46 PM 2406

    PasteMode - How to prevent pasting of formatted text

    What does PasteMode do?  The values I see for this undocumented property are: Default, Disabled, and Text.  In our implementation of FTB, we are not allowing users to set the font face or font size.  However, if (at least on Win) user copies some formatted text from an IE page or Word doc and pastes it into FTB, the text is pasted as formatted (i.e. the formatting is retained).  This allows users to introduce different font faces/sizes by virtue of the pasted text (event though we do not provide those menus to them).  Is there a way to prevent this?  I realize it may just be a function of the OS clipboard and beyond the scope of the control.
  •  12-06-2004, 4:37 PM 2409 in reply to 2406

    Re: PasteMode - How to prevent pasting of formatted text

    I second this need. I have the same situation. How can we handle this with eith 3.0 or 2.x ??

    Thanks,

    Mike
  •  12-06-2004, 9:04 PM 2410 in reply to 2406

    Re: PasteMode - How to prevent pasting of formatted text

    I was actually going to request this feature to be added as well.  Cutesoft's product prompts to remove word formatting when you try to paste it into their control. 

    I was wondering if FreeTextBox could do the same.  I know the option is there on the toolbar to remove word formatting, but I would like to see it on the paste event.

    This feature request gets my vote :)


    Drone

    No one knows everything, so I come here to learn and teach.
  •  12-08-2004, 11:51 AM 2428 in reply to 2406

    Re: PasteMode - How to prevent pasting of formatted text

    A couple notes I'd like to add to my original post.  When I looked through the JavaScript source code, it appears that the FTB control's PasteMode property value (Default, Disabled, Text) is passed to the "FTB-FreeTextBox.js" JavaScript (see code snippet below).  There is logic in the JS which appears to be do what I want: for PasteMode=Text, it looks like it uses a regular expression to strip out all HTML tags.  The problem is that it is not working; even when PasteMode is Text, the formatting is preserved when pasting rich text into the FTB text area.  Please advise on whether this is a bug and when it might be fixed.

    FTB_FreeTextBox.prototype.CapturePaste = function(ev) {
     return true;
      switch (this.pasteMode) {
       case FTB_PASTE_DISABLED:
        return false;
       case FTB_PASTE_TEXT:
       var text = window.clipboardData.getData('Text');
       text = text.replace(/<[^>]*>/gi,'');
       this.InsertHtml(text);
       return false;   
       default:
       case FTB_PASTE_DEFAULT:
        // do nothing
        return true;
      }  
    }
  •  12-09-2004, 8:38 PM 2451 in reply to 2428

    Re: PasteMode - How to prevent pasting of formatted text

    This is now fixed. The main problem in the download was the "return true;" statement. Mozilla cannot access the clipboardData object, so if set to Text, it will simply disable pasting.

    JD

    John Dyer
    freetextbox.com
  •  12-05-2005, 4:22 AM 5320 in reply to 2410

    Re: PasteMode - How to prevent pasting of formatted text

    This property prevens pasting just only from Control-V.
    If I use Paste from context menu or browser menue (edit) I can paste not only when paste is disabled but alos the full formatted html, no matter what the setting of FTBis. :S
  •  05-16-2008, 1:04 PM 9158 in reply to 2451

    Re: PasteMode - How to prevent pasting of formatted text

    I could be wrong, but I think the code could still use improvement. The executeCommand method returns "undefined" in IE if "Paste via script" is disabled. This does NOT throw an error, so you never get the message. Because of this it took me a while to figure out what was going on in our environment because when pasting nothing would happen (no error, no alert) when PasteMode was set to Default.

    Original Code:
    case FTB_PASTE_DEFAULT:
    try{
        this.ExecuteCommand('paste');
    }catch(e){
        alert('message...');
    }
    return true;
    Possible Improvement:
    case FTB_PASTE_DEFAULT:
    try{
        if(!this.ExecuteCommand('paste')) alert('message...');
    }catch(e){
        alert('message...');
    }
    return true;
    Likewise the FTP_PASTE_TEXT does not seem to test for this condition ("Paste via script" set to disabled). The behavoir there is for a javascript error to be thrown, but then pasting as usual to occur (i.e. HTML included). At least an error was thrown there for me to know something was wrong, but an informative message would help developers out a lot.

    Original Code:
    if(window.clipboardData){
        //work
    }else{
        alert('Your browser does not support rich text pasting');
    }

    Possible Improvement:
    if(typeOf clipboardData == 'undefined'){
    alert('Your browser does not support rich text pasting');
    }else if(clipboardData.getData('Text') == 'undefined'){
    alert('Your browser is set to DENY scripted pasting');
    }else{
    //do work
    }
    Additionally, I see this as a bug... because the only way to paste in a ftb with the browser set to disable scripted pasting is to set it PasteMode to Text, causing the error, which then actually diverts the method to NON Text only pasting. I think there should be a way to set it to "Do not handle scripting" or something like that, and for the alerts detecting the browser being set to disable scripted pasting to inform the developer that they must use this setting. An even better solution would be to somehow work around the problem. Because ftb's onClientTextChanged event does not gracefully execture when you are also changing the text (wordClean onTextChanged, then write back to the ftb) AND there is no blur event to do it after the user blurs, this is very problematic. The only options I see are to clean the text boxes up on submit click and letting the user know if any changes were made so they can review the outcome prior to final submit.

    I for one would like to see a onBlur event added as well. This could come in handy for many reasons.

    Thanks for a great product that works great in most configurations.
View as RSS news feed in XML
www.freetextbox.com