This is a migrated thread and some comments may be shown as answers.

Prevent copy&paste image from web browser

8 Answers 225 Views
Editor
This is a migrated thread and some comments may be shown as answers.
shunman
Top achievements
Rank 1
shunman asked on 24 Apr 2015, 05:07 AM

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.}

 

8 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 28 Apr 2015, 07:16 AM
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.

 
0
shunman
Top achievements
Rank 1
answered on 04 May 2015, 05:15 AM

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

0
shunman
Top achievements
Rank 1
answered on 04 May 2015, 05:20 AM

One more, 

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

0
Ianko
Telerik team
answered on 04 May 2015, 01:37 PM
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.

 
0
shunman
Top achievements
Rank 1
answered on 04 May 2015, 02:52 PM

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.

0
Ianko
Telerik team
answered on 05 May 2015, 07:15 AM
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.

 
0
shunman
Top achievements
Rank 1
answered on 06 May 2015, 12:46 AM

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.

0
Ianko
Telerik team
answered on 07 May 2015, 10:07 AM
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.

 
Tags
Editor
Asked by
shunman
Top achievements
Rank 1
Answers by
Ianko
Telerik team
shunman
Top achievements
Rank 1
Share this question
or