homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Remove Formatting Using Javascript

Msg#: 4460573 posted 8:30 pm on Jun 1, 2012 (gmt 0)

I have been working on modifying a javascript that will allow users of my website to copy/paste without bringing along all those HTML formats. I am not fluent with Javascript so for me it is a lot of hit and miss, usually with mostly misses. The script was originally designed to add a copywrite notice and link to any copy and pasted text. One problem I have been having I was able to do a sort of patch for instead of an actual fix. I changed the background color to white because the webpage body is gray.

What I want to do is instead of CHANGE colors, or fonts, or whatever, I want to just DROP all those unwanted formats sort of like right clicking and paste as unformatted text. I would sure welcome any suggestions or help anyone could offer.

So far this is what I have:

<script type="text/javascript">
function Format() {
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var copytext = selection;
var newdiv = document.createElement('div');
newdiv.style.background = "white";
newdiv.innerHTML = copytext;
window.setTimeout(function() {
document.oncopy = Format;



Msg#: 4460573 posted 7:26 am on Jun 9, 2012 (gmt 0)

I'm not too sure what you mean by "HTML formats". Nevertheless, besides IE, there is no way to access text that has been copied to clipboard in JavaScript. If I recall correctly, you can capture selected text, but that will not affect anything when the user copies and pastes.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved