By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Selecting the content of a div in a Button click.

P: n/a
I need a solution to my problem.
the problem is

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

Nov 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
visu wrote:
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/
Nov 29 '06 #2

P: n/a
visu wrote:
I need a solution to my problem.
the problem is

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
So you want the plaintext-content of a div? Look at the normalize()
function.

--
Martijn Saly
Nov 29 '06 #3

P: n/a
Martijn Saly wrote:
visu wrote:
I need a solution to my problem.
the problem is

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

So you want the plaintext-content of a div? Look at the normalize()
function.

--
Martijn Saly
Thanx thanx.. thanx a lot..
i really i does the thing what i want exactly..
Thanx for ur solution.

Regards,
Visu.

Dec 2 '06 #4

P: n/a
visu wrote:
Martijn Saly wrote:
visu wrote:
I need a solution to my problem.
the problem is
>
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. wh
y? 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
>
So you want the plaintext-content of a div? Look at the normalize()
function.

--
Martijn Saly
Thanx thanx.. thanx a lot..
i really i does the thing what i want exactly..
Thanx for ur solution.

Regards,
Visu.
sorry
i mean, it really does the thing what i want exactly..

Dec 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.