Prevent copy&paste image from web browser

9 posts, 0 answers
  1. shunman
    shunman avatar
    77 posts
    Member since:
    Jul 2011

    Posted 24 Apr 2015 Link to this post

    Hello Telerik Support Team.

     I'm using dll 2014.1.403.40 version.

    I would like to prevent pasting image into editor from web browser copy on context menu.

    I had seen your editor demo here (http://demos.telerik.com/aspnet-ajax/editor/examples/cleaningwordformatting/defaultcs.aspx)

    Demo is working good for blocking any pasting image by Control+V or paste on context menu.

    I implemented sample project using your demo source unfortunately it does not work!!!!!!!!!!.

    My test procedure is here.

    1. Right click on the image in IE browser (That will shows browser context menu)

    2. Click "Copy"

    3. Pasting image into editor by pressing Control + V

    4. Editor shows pasted image. (<--- Your demo is not shows image)

     What is the problem? I need to same feature like your demo.

     I'm attaching my sample project thank you.

     

    ASPX:

    01.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
    02. 
    03.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    04. 
    06.<head runat="server">
    07.    <title></title>
    08.    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    09.</head>
    10.<body>
    11.    <form id="form1" runat="server">
    12.        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    13.            <Scripts>
    14.                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
    15.                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    16.                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    17.            </Scripts>
    18.        </telerik:RadScriptManager>
    19.        <script type="text/javascript">
    20.            //Put your JavaScript code here.
    21.            function OnClientSubmit(sender, args) {
    22.                sender.fire("FormatStripper", { value: "WORD" });
    23.            }
    24.        </script>
    25.        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    26.        </telerik:RadAjaxManager>
    27.        <div>
    28.            <telerik:RadEditor runat="server" OnClientSubmit="OnClientSubmit" ID="RadEditor1"
    29.                SkinID="BasicSetOfTools" Width="420px" Height="300px" EnableResize="false">
    30.                <Content>
    31.                    <p class="MsoNoSpacing" style="margin: 0in 0in 0pt;"><span class="MsoIntenseEmphasis" style="color: #4f81bd;"><strong><em><span style="font-family: calibri;">     <br />
    32.                    Experiment with the various options of the StripFormattingOptions setting for cleaning Word formatting.</span></em></strong></span></p>
    33.                    <p class="MsoNoSpacing" style="margin: 0in 0in 0pt;"><span class="MsoIntenseEmphasis"><strong><em><span style="color: #4f81bd; font-family: calibri;">       
    34.                        The content here has MS Word formatting which you can strip on submit by clicking on the "Submit and Clean" button above.<o:p></o:p></span></em></strong></span></p>
    35.                </Content>
    36.            </telerik:RadEditor>
    37.        </div>
    38.    </form>
    39.</body>
    40.</html>

    CS:

    01.using System;
    02.using System.Web;
    03.using System.Web.UI;
    04.using System.Web.UI.WebControls;
    05. 
    06.using System.Data;
    07.using System.Configuration;
    08.using System.Web.Security;
    09.using System.Web.UI.WebControls.WebParts;
    10.using System.Web.UI.HtmlControls;
    11.using Telerik.Web.UI;
    12. 
    13.public partial class Default : System.Web.UI.Page
    14.{
    15.    protected void Page_Load(object sender, EventArgs e)
    16.    {
    17.        if (!IsPostBack)
    18.        {
    19. 
    20.            RadEditor1.StripFormattingOptions = EditorStripFormattingOptions.All;
    21. 
    22.        }
    23.    }
    24.}

     

  2. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 28 Apr 2015 Link to this post

    Hello,

    The used option is not intended to prevent pasting of images.

    You should handle this manually via custom functionality that strips out the undesired content. You can capture the paste event and the text to be inserted with the OnClientPasteHtml event.

    Regards,
    Ianko
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. shunman
    shunman avatar
    77 posts
    Member since:
    Jul 2011

    Posted 04 May 2015 in reply to Ianko Link to this post

    Hello Telerik Team.

    the OnClientPasteHtml  can't detect pasting image via ctrl + v option.

    Your demo exactly block paste option also ctrl + v. 

    I would like to how did it.

    thanks

  5. shunman
    shunman avatar
    77 posts
    Member since:
    Jul 2011

    Posted 04 May 2015 in reply to shunman Link to this post

    One more, 

    Your demo blocked paste image when StripFormattingOptions is "All" and IE10

  6. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 04 May 2015 Link to this post

    Hello Shunman,

    Could you clarify which is the online demo you are referring to?

    Regards,
    Ianko
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  7. shunman
    shunman avatar
    77 posts
    Member since:
    Jul 2011

    Posted 04 May 2015 in reply to Ianko Link to this post

    Demo link here.

    http://demos.telerik.com/aspnet-ajax/editor/examples/cleaningwordformatting/defaultcs.aspx

     and  StripFormattingOptions Configurator check "All" only

    Trying to test IE browser

    1. mouse right-click context menu on image "Copy Image"

    2. Press Ctrl+v into editor  or mouse right-click context menu "Paste"

    3. Image did not paste.

  8. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 05 May 2015 Link to this post

    Hi Shunmanc,

    The answer to your question—Why StripFormattingOptions All option, does no pastes images?—is described in the description of the demo, where the All option is explained—All: strips all HTML formatting and pastes plain text.

    As the IMG tag does not have innerHTML or innerText, nothing is pasted. This is done by a plain HTML tag stripping. See this Stackoverflow thread—http://stackoverflow.com/questions/785715/how-can-i-strip-html-tags-from-a-string-in-asp-net.

    As for the OnClientPasteHtml event, on my end fires every time, and I am unable to define why the behavior might be different on your end. Check out this screencast which shows my tests.

    Regards,
    Ianko
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  9. shunman
    shunman avatar
    77 posts
    Member since:
    Jul 2011

    Posted 05 May 2015 in reply to Ianko Link to this post

    Hello Telerik Team.

    I tested your latest trial dll "2015.1.401.45"

    It works fine likes demo site. everything is good.

     but our  telerik dll still have problem.

    I would like to know our telerik version "2014.1.403.40" is bug.

  10. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 07 May 2015 Link to this post

    Hi Shunman,

    If you can definitely define that the bug has been resolved for the latest version, it is recommended to upgrade to that version. When it comes to bug fixes, it is always better to use the official version of the release which exposes the fix, than using temporary workarounds. They can cause issues to support feature upgrades.

    Regards,
    Ianko
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017