htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
Remove all HTML tags onPaste


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


chrisTheMan
Novice

Oct 14, 2004, 10:09 AM

Post #1 of 11 (7408 views)
Shortcut
Remove all HTML tags onPaste Can't Post

Hello,

I did some research about this topic and did find heaps of entries, but nothing which helped me. So I hope someone knows something...

I would like to remove all HTML-tags when someone is pasting something into a HTMLarea. What I so far did is, that I changed the function _wordClean:


Code
 HTMLArea.prototype._wordClean = function() { 
var mytext = window.clipboardData.getData('Text');
window.clipboardData.clearData('Text');
window.clipboardData.clearData('HTML');
window.clipboardData.setData('Text', mytext);
};

My problem is now:
  1. It is not working on right click
  2. On CTR+V it is only working after the second time


Any ideas?

Thanks in advance,
chris


TripleTuned
Novice

Oct 14, 2004, 2:10 PM

Post #2 of 11 (7392 views)
Shortcut
Re: [chrisTheMan] Remove all HTML tags onPaste [In reply to] Can't Post

Hello Chris

Search in htmlarea.js for:


Code
  

case "paste":
try {


this._doc.execCommand(cmdID, UI, param);
if (this.config.killWordOnPaste)
this._wordClean();

And do the following with the fragment:


Code
    //old this._doc.execCommand(cmdID, UI, param); 
//old if (this.config.killWordOnPaste)
//old this._wordClean(); // TripleTuned Code

var input = window.clipboardData.getData("Text");
this._doc.execCommand(cmdID, UI, input);
// END TripleTuned Code



Greez and keep on rocking, dude!
Triple Tuned Cool Check out my latest Tracks at www.tripletuned.com !


chrisTheMan
Novice

Oct 14, 2004, 2:47 PM

Post #3 of 11 (7389 views)
Shortcut
Re: [TripleTuned] Remove all HTML tags onPaste [In reply to] Can't Post

Rock'n'Roll man,

your solution works just perfect for Ctrl+V, but it does not work for the right mouse click...

Is there a solution too?

Cheers,
chris


TripleTuned
Novice

Oct 14, 2004, 3:08 PM

Post #4 of 11 (7388 views)
Shortcut
Re: [chrisTheMan] Remove all HTML tags onPaste [In reply to] Can't Post

unfortunately not. And you can still drag and drop a whole content from MSWord into the htmlArea, and the html tags are not removed. Any solution for this?


chrisTheMan
Novice

Oct 14, 2004, 5:13 PM

Post #5 of 11 (7385 views)
Shortcut
Re: [TripleTuned] Remove all HTML tags onPaste [In reply to] Can't Post

sorry, I did not get this one. Are you saying, that there is no solution for the right click and paste with the mouse problem? Or don't you have a solution?

Yes I still can drag and drop formated content from MS Word to the HTMLarea by using the mouse and no, I don't have a solution to avoid this but I would love to have one.


TripleTuned
Novice

Oct 15, 2004, 1:19 AM

Post #6 of 11 (7377 views)
Shortcut
Re: [chrisTheMan] Remove all HTML tags onPaste [In reply to] Can't Post

Sorry for making confusenes.

Unfortunately I haven't a solution for the right click problem.

And there is also the problem that you can drag and drop formated content from MS Word to the htmlArea.

I have no clue how to solve both problems. Maybe someone else?


lichteblau
New User

Oct 15, 2004, 8:02 AM

Post #7 of 11 (7358 views)
Shortcut
Re: [TripleTuned] Remove all HTML tags onPaste [In reply to] Can't Post

With some help from kyberfabrikken (http://www.interactivetools.com/forum/gforum.cgi?post=35203#35203)
I have the attached code for markup stripping, which works for both copy&paste and drag&drop. (Probably needs Internet Explorer and the ContextMenu plugin.)

The remaining problem is that I would like to strip markup only when text is pasted from external programs like Word. Currently markup is stripped even when copy&pasting _within_ HTMLarea.

Oh, and the "drop" is cancelled, which leads to text being copied instead of moved when using drag&drop.


Code
        editor.onGenerate = function() { 
with (editor) {
var d = HTMLArea.is_ie ? _doc.body : _doc;
HTMLArea._addEvents(
d,
["paste", "dragdrop", "drop"],
function (e) {
var e;
if (HTMLArea.is_ie)
e = self.editor._iframe.contentWindow.event;
else
e = event;
if (e.type == "paste") {
var text = window.clipboardData.getData("Text");
window.clipboardData.setData("Text", text);
return true;
} else {
var text = e.dataTransfer.getData("Text");
_createRange(_getSelection()).text = text;
return false;
}
});
}
};



(This post was edited by lichteblau on Oct 15, 2004, 8:04 AM)


chrisTheMan
Novice

Oct 15, 2004, 2:59 PM

Post #8 of 11 (7335 views)
Shortcut
Re: [lichteblau] Remove all HTML tags onPaste [In reply to] Can't Post

very cool. It works for me!

Thanx


(This post was edited by chrisTheMan on Oct 20, 2004, 10:14 AM)


driz
Novice

Oct 28, 2004, 4:25 AM

Post #9 of 11 (7149 views)
Shortcut
Re: [lichteblau] Remove all HTML tags onPaste [In reply to] Can't Post

Hi,

Is it already possible to use this modification in htmlArea 2? If so, could you please explain what code I have to replace with what or where to implement this piece of code?

Thank you!

Andris


chrisTheMan
Novice

Oct 28, 2004, 5:35 AM

Post #10 of 11 (7142 views)
Shortcut
Re: [driz] Remove all HTML tags onPaste [In reply to] Can't Post

For me it worked with the following code in htmlArea 2:

change
editdoc.body.onpaste = function() { editor_event(objname, 100); }
to


Code
 //editdoc.body.onpaste   = function() { editor_event(objname, 100); } 
editdoc.body.onpaste = function() { cleanup_pasted(objname); }



Paste the following function somewhere at the end of your editor.js


Code
 function cleanup_pasted(objname) { 
var mytext = window.clipboardData.getData('Text');
window.clipboardData.clearData('Text');
window.clipboardData.clearData('HTML');
window.clipboardData.setData('Text', mytext);
}



AG
Novice

Feb 10, 2005, 12:51 PM

Post #11 of 11 (6241 views)
Shortcut
Re: [lichteblau] Remove all HTML tags onPaste [In reply to] Can't Post

Hi, can you tell me where to put this code? I am assuming it is at the end of my htmlarea.js file. I have it there, but it does not seem to work. Can anyone steer me in the right direction?

Thanks,

 
 
 


Search for (options)