How to Copy highlighted text to richtext box editor by adding Quote Tags using Javascript? RRS feed

  • Question

  • User-424509365 posted

    I am developing website using asp.net and inside of it there is a feature like "Quote" in this website. So user have the ability to highlight the text that he want to quote and press the quote button exactl like happening in this website

    But I am not a expert in javascript. So far I achieved was this

        function handlePaste(e) {
            var clipboardData, pastedData;
            // Stop data actually being pasted into div
            // Get pasted data via clipboard API
            clipboardData = e.clipboardData || window.clipboardData;
            pastedData = clipboardData.getData('Text');
            // Do whatever with pasteddata
        document.getElementById('reference-post-content').addEventListener('paste', handlePaste);

    In there if highlighted a text and press CTRL+C and then again if i press CTRL+V then it will give a popup message by displaying that highlighted text. But this is not what i wanted. What I want is that text should go to richtextbox below if user click quote btn. Also it should go to rich textbox like this.

    message is in a thread in which the user is a THREAD_PARTICIPANT. I'm afraid I can never state these

    I also have this impmentation. I have a tinymce rich textbox to post something.

    I found this javascript function when I inspect the elements of this website

        $("#quote-action") != null && $("#quote-action").bind("click", function () {
            var n = null, t = $("#quote-createdby").val();
            if (window.getSelection && (window.getSelection() || window.getSelection().extentNode != null) && window.getSelection().rangeCount > 0) {
                var i = window.getSelection(), u = i.getRangeAt(0).cloneContents(), r = document.createElement("div"); r.appendChild(u); n = r.innerHTML; i.removeAllRanges()
            else document.selection && (n = document.selection.createRange().htmlText, document.selection.empty()); (n == null || n == "") && (n = $("#reference-post-content").html());
            $.ajax({ type: "POST", url: "/soa/post/body/removeprettyprinttags", data: { body: n }, success: function (i) { i != null && i.result != "" && (n = i.result); tinyMCE.activeEditor.focus(); tinyMCE.activeEditor.selection.moveToBookmark(tinyMCE.activeEditor.updatedSelectionBookmark); tinyMCE.execCommand("mceInsertContent", !1, '
    ' + n + "
    "); UpdateBookmark(tinyMCE.activeEditor) }, error: function (i, r, u) { isProd || alert("Error: " + r + " " + u); tinyMCE.activeEditor.focus(); tinyMCE.activeEditor.selection.moveToBookmark(tinyMCE.activeEditor.updatedSelectionBookmark); tinyMCE.execCommand("mceInsertContent", !1, '
    ' + n + "
    "); UpdateBookmark(tinyMCE.activeEditor) } }) }); </script>

    But still its not working

    So how to do this? Can somebody provide the code that working on this website?

    Tuesday, November 1, 2016 5:05 AM

All replies

  • User347430248 posted

    Hi Klprageeth,

    use the code mentioned below.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm9.aspx.cs" Inherits="WebApplication37.WebForm9" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <style type="text/css">
        <form id="form1" runat="server">
        <textarea id="quote" cols="50" rows="5">
    Some text here
    <div id="output"></div>
    var quotearea = document.getElementById('quote')
    var output = document.getElementById('output')
    quotearea.addEventListener('mouseup', function(){
        if (this.selectionStart != this.selectionEnd){ // check the user has selected some text inside field
            var selectedtext = this.value.substring(this.selectionStart, this.selectionEnd)
            output.innerHTML = selectedtext
    }, false)




    Wednesday, November 2, 2016 4:45 AM