470,625 Members | 2,059 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,625 developers. It's quick & easy.

capture selected text from a page

can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse out.

here is the code

[HTML]<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var captured = "";
function captext()
{
alert('You have selected'+ captured);
}
var text = "";
function getActiveText(e) {

// Sets text MSIE or Netscape active
// text based on browser, puts text in form
text = (document.all) ? document.selection.createRange().text : document.getSelection();
captured = text;
captext();
document.theform.text.value = text;
return true;
}
document.onmouseup = getActiveText;
if (!document.all) document.captureEvents(Event.MOUSEUP);
// End -->
</script>
<script type="text/javascript">
function popup()
{
var wind1=null;
var tmp=null;
wind1 = window.open('', 'displayWindow', 'width=400,height=300,status=no,toolbar=no,menubar =no,scrollbars=1');
wind1.document.write("<script> function alert1(f){");
wind1.document.write("var frmdst=f.ta.value;");
wind1.document.write("window.opener.tmp=frmdst;");
wind1.document.write("window.opener.getValues();") ;
wind1.document.write("window.close();");
wind1.document.write("}<\/script>");
wind1.document.write("<html><body><form action='#' name='myform' method='post'><TEXTAREA rows='2' cols='20' name='ta'></TEXTAREA><br><INPUT type='button' value='save' onclick='javascript:alert1(this.form);'><INPUT type='button' value='cancel' onclick='javascript:window.close();'></form></body></html>");
}
function getValues()
{
document.forms["source"].elements["srctext"].value = tmp;
}
</script>
</HEAD>
<BODY>

<center>
<form name=theform>
Selected text: <input type=text name=text value="" size="20">
<br><br>
Entered text: <input type=text name=text1 value="" size="20">
</form>
</center>

<p>
<p>Hi All,</p>
<p>&nbsp;</p>
<p>this is the javascript that will capture the value highlighted and store in a
variable.</p>

</body>
</html>[/HTML]
Mar 19 '08 #1
1 2550
acoder
16,027 Expert Mod 8TB
can any one help me to write code to capture selected text from a page but problem is that i am not able to decide where to call the functio.in this case the function is called in all cases of mouse out.
You mean mouseup? It depends on your requirements. Maybe you want to call it when a button is clicked?
Mar 20 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by George Hester | last post: by
9 posts views Thread by lkrubner | last post: by
7 posts views Thread by Lit | last post: by
13 posts views Thread by =?Utf-8?B?RG9uYWxkIEZpc2hlcg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.