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

Suppress javascript error during paste

5 Answers 113 Views
Editor
This is a migrated thread and some comments may be shown as answers.
First
Top achievements
Rank 1
First asked on 08 Feb 2011, 10:37 AM
Hi there,

I'm  using radEditor and found annoying error that must be solved.
What happened was the user wanted to paste HTML content from google finance to radEditor.
And it triggered javascript error, object not found in Internet Explorer 8.
For more details, I enclosed the google finance content at the end of this page.

After tiring and restless debugging, much testing, I still couldn't suppress the javascript error.
I use the onerror syntax to capture all javascript error, but it doesn't work.
window.onerror = function () {
    alert("Error captured");
}

Finally, I found the culprit. The image tag has javascript onload event. Thus I use the following crude code to replace the onload event.
This works for future use, but it sill doesn't solve the issue when the user pasted the content.
function OnClientPasteHtml(sender, args) {
    alert("OnPaste");
    var value = args.get_value();
    alert(value);
    value = value.replace(/ on/g, " _on");
    args.set_value(value);
}

In fact, I tried to paste the google finance content, I received the same javsacript error in this page.
I tried to use OnClientCommandExecuting radEditor client event, hoping I can modiy the clipboard content before it's being paste into radEditor. But the args.get_value() returns empty.

My questions,
1. How to suppress all javascript error in radEditor?
2. How to modify the clipboard content before it's being paste to radEditor. OnClientPasteHtml is too late.

Thank you.




http://www.google.com/finance

Huffington Deal Raises Question: What Site Will Be Sold Next?
By EVELYN M. RUSLI In agreeing to buy The Huffington Post for $315 million, AOL is putting what appears to be a significant premium on the ability to attract and build a community of readers.
Can the Huffington Post save AOL?  
Newspaper stocks jump on content hopes  
Market Chart
12,161.63 +69.48 (0.57%)
1,319.05 +8.18 (0.62%)
2,783.99 +14.69 (0.53%)

5 Answers, 1 is accepted

Sort by
0
Stanimir
Telerik team
answered on 11 Feb 2011, 10:12 AM
Hello First,

1. How to suppress all javascript error in radEditor?
What you can try is to set the window.onerror = function () in the content area of the editor, which is an IRAME element. In order to do this set the OnClientLoad property of the control and add the following javascript:
declaration example:
<telerik:RadEditor ID="RadEditor1" runat="server" OnClientLoad="OnClientLoad"></telerik:RadEditor>
javascript code:
function OnClientLoad(editor, args)
{
    editor.get_contentWindow().onerror = function ()
    {
        alert("Error captured");
        return false;
    }
}

2. How to modify the clipboard content before it's being paste to radEditor. OnClientPasteHtml is too late. -
In General the OnClientPasteHtml event is the place to modify the pasted content. However in your case will not work because the content is causes error.

At this point the solution that I can provide you with works only in IE. Here is an example javascript code:
function OnClientLoad(editor, args)
{
    var element = document.all ? editor.get_document().body : editor.get_document();
    $telerik.addExternalHandler(element, "paste", function ()
    {
        var clipboardText = window.clipboardData.getData("Text");
                //here you modify the content
        clipboardText += "Text is modified!";
        window.clipboardData.setData("Text", clipboardText);
    });
}




All the best,
Stanimir
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Asim
Top achievements
Rank 1
answered on 31 Jan 2013, 10:58 AM
Hello Stanmir,

I am also experiencing a similar problem where when ever i am trying to paste something at radEditor. Its giving me the "Error: Access is denied. But it still paste it. I tried your solution about suppressing the error and that's what i want to do but that didn't worked for me. Please could you help me out find out any the other soultion.

Asim
0
Rumen
Telerik team
answered on 04 Feb 2013, 01:14 PM
Hello,

You can try the following two approaches:
- Set the StripFormattingOptions to "NoneSupressCleanMessage"
- OR set the ContentAreaMode to DIV

and test again.

Best regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Asim
Top achievements
Rank 1
answered on 05 Feb 2013, 12:47 PM
Hi Rumen,

Thanks for your reply, your solution worked, i had to use both suggestions to make it work. I am also having another problem with IE9 with radEditor. forgive me if i am asking in the wrong thread. But now i IE9 i have a problem with "Enter Key" by pressing "Enter Key" we should go to the next line but somehow in IE 9 its not working in that way. I tried couple of solutions from telerik forum threads nut none of them worked, in one of the thread it was suggested that we should upgrade to the latest version and in the next thread it was suggested to to use "RadEditor1.DisableFilter(EditorFilters.FixEnclosingP)" which i also tried but was not very helpful. 
can you help me out here that how handle that issue ?

Best Regards
Asim
0
Rumen
Telerik team
answered on 07 Feb 2013, 07:01 AM
Hi Asim,

You can try to set the NewLineMode property to "P". If this does not fix the problem, try the latest version Q3 2012 SP2. If the issue still persists, isolate it in a simple working project and send it for examination.

Best regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Editor
Asked by
First
Top achievements
Rank 1
Answers by
Stanimir
Telerik team
Asim
Top achievements
Rank 1
Rumen
Telerik team
Asim
Top achievements
Rank 1
Share this question
or