I ll have a button in page ... and when i click it .. content of a div
tag has to be get selected (i.e what we normally do with mouse to
selecting some part of a page).. then i can do CTRl+C to copy the
selected div content.. to paste it in MS Word or in any other external
application..
i ve tried the select + copy + paste sequence with the use of
temporary text area element to store the innerHTML of Div tag and
copied to Clipboard. but while pasting the selected content in MS word
it appears like the textual tags not html formatted.. but when u do the
same with mouse clicks and drags u get the formatted pasting in ms
word. why? is it possible to just let to user to select a div while
clicking a button, pressing ctrl+c to copy and paste the content in
another application(ms word etc)?.
Plz help me
> I ll have a button in page ... and when i click it .. content of a div
>
> tag has to be get selected (i.e what we normally do with mouse to
> selecting some part of a page)
<script type="text/javascript">
function selectNode (node) {
var selection, range, doc, win;
if ((doc = node.ownerDocument) && (win = doc.defaultView) && typeof
win.getSelection != 'undefined' && typeof doc.createRange != 'undefined'
&& (selection = window.getSelection()) && typeof
selection.removeAllRanges != 'undefined') {
range = doc.createRange();
range.selectNode(node);
selection.removeAllRanges();
selection.addRange(range);
}
else if (document.body && typeof document.body.createTextRange !=
'undefined' && (range = document.body.createTextRange())) {
range.moveToElementText(node);
range.select();
}
}
</script>
<div id="div1">
<h2>Example text</h2>
<p>Example paragraph. Kibology for all. All for Kibology.</p>
</div>
<div>
<input type="button" value="select div text"
onclick="window.selectNode(document.getElementById('div1'));">
</div>
works with Mozilla and IE.
--
Martin Honnen
http://JavaScript.FAQTs.com/
So you want the plaintext-content of a div? Look at the normalize()
function.
--
Martijn Saly
Regards,
Visu.
sorry
i mean, it really does the thing what i want exactly..