views:

940

answers:

7

Hi all,

I'm having a problem with non-displayed HTML elements being copied to the clipboard, and then displayed when the content is pasted into MS Word, Outlook, etc.

For example:

<p>Hello</p>
<p style="display: none;">I'm Hidden</p>
<p>World</p>

If I view that HTML in a browser, copy the text to my clipboard, then paste into Outlook, the middle paragraph remains hidden. Good news.

However, in this example:

<p>Hello</p>
<input type="text" value="I'm not hidden" style="display: none;" />
<p>World</p>

If I do the same - copy to clipboard, paste into Outlook - the text input is visible.

Is there any way I can supress this? (Without resorting to telling users to select "Keep text only" in Outlook.)

Thanks!

+3  A: 

Use type='hidden' instead of type='text' for the input box and wrap this inside a div with style set to display: none

rahul
Hi- thanks for the quick reply. Unfortunately, this problem is happening for other form fields too, where I don't have the "hidden" option (eg: <select>). A "display:none" container doesn't fix it either - <div style="display: none;"><select style="display: none;"> etc. - still displays when pasted.
stubotnik
Sorry for interrupting. But whats the use of these controls if they are not shown in the page.
rahul
No problem - they're show/hidden when needed using JavaScript.
stubotnik
Are all these shown/hidden controls inside same div or are they in different containers in the page??? Can you use asp:Panel instead of div as container of these elements??
rahul
(1) The immediate parents of these elements are not the same container (2) Not using asp...
stubotnik
A: 

Anybody find a resolution to this? I have a template report that my web app sends out with some sections hidden () that are showing up in some situations. It appears that the outlook HTML interpreter is re-writing some of the HTML and not respecting previously set style elements...

A: 

What happens if you use the visible attribute?

j3frea
still no joy I'm araid
stubotnik
"I'm afraid" rather...
stubotnik
A: 

You should be aware that hiding HTML with CSS only works if the renderer supports all the CSS styles.

Just because you do not see copy/pasted HTML in Outlook does not mean the data is not already there.

I am not sure what you are actually trying to achieve: Why do you need your users to copy HTML into Outlook at all?

devio
I don't want them to copy HTML into Outlook - but they insist! :-)(this is for an intranet app.)
stubotnik
A: 

How about wrapping appropriate elements in div tags and then "display: none" those divs when appropriate. i.e:

<p>Hello</p>
<div style="display: none;"><input type="text" value="I'm not hidden" /></div>
<p>World</p>

Also, I have sometimes found that having the closing / in the tag causes odd behaviour on occasion, perhaps try without it...

j3frea
That didn't make any difference unfortunately - thanks anyway!
stubotnik
+3  A: 

It sounds like you need to have the JavaScript create the DOM sections rather than just changing CSS styles. Instead of changing the display property of the "I'm hidden" paragraph, have the JavaScript create that element when you want it to display, and remove it whan you want to hide it.

If the elements are complicated enough, then perhaps you can have them at the bottom of the document with "display:none", but then move them into the place where you want them visible.

John Saunders
I think you're right. It seems that Outlook is always going to display my CSS-hidden content, so this is probably the only reasonable way to achieve what I'm after. Thanks!
stubotnik
A: 

If you require users to copy content, I'd recommend dropping that content in a <textarea /> and allowing them to select/copy by clicking a button. It can be difficult to select exactly the right text in browsers.

Brandon Gano
dropping the content in a ____? :-)
stubotnik
The angle brackets won again...
Brandon Gano