Search code examples
jqueryasp.net.netckeditorfreetextbox

Possible to let the editor Recognize the link


I m building a system which have editor ( html editor ) freetextbox or ckeditor no matter

my Question !

Its Possible to let the editor Recognize the link after paste it in the editor ? for example : if i copy and paste the following link
http://www.youtube.com/watch?v=uI40vztICwM&feature=g-logo

then the editor shall play youtube video

if not ! please there are any events that i can handle in javascript after paste any content in the editor ?


Solution

  • Please Have Below the code :

    <script>
    
        CKEDITOR.on('instanceReady', function(e){
         var editor = e.editor;
         editor.on('paste', function(evnt){
    
         var data = evnt.data;
    
          // youtube recognize 
           data.dataValue = data.dataValue.replace(/(?:http:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, '<iframe width="420" height="345" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>');
    
          //image recognize
    
             data.dataValue = data.dataValue.replace(/(https?:\/\/.*\.(?:png|jpg))/i,'<img src="$1" width="450" height="199" alt="alt description" title="image title" class="image_classes" />');
    
           alert(data);
           data.type = 'html';
    
    
         });
         });
    
    
            </script>