capture selected text from a page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • destiny007
    New Member
    • Feb 2008
    • 8

    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="JavaS cript">
    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.select ion.createRange ().text : document.getSel ection();
    captured = text;
    captext();
    document.thefor m.text.value = text;
    return true;
    }
    document.onmous eup = getActiveText;
    if (!document.all) document.captur eEvents(Event.M OUSEUP);
    // End -->
    </script>
    <script type="text/javascript">
    function popup()
    {
    var wind1=null;
    var tmp=null;
    wind1 = window.open('', 'displayWindow' , 'width=400,heig ht=300,status=n o,toolbar=no,me nubar =no,scrollbars= 1');
    wind1.document. write("<script> function alert1(f){");
    wind1.document. write("var frmdst=f.ta.val ue;");
    wind1.document. write("window.o pener.tmp=frmds t;");
    wind1.document. write("window.o pener.getValues ();");
    wind1.document. write("window.c lose();");
    wind1.document. write("}<\/script>");
    wind1.document. write("<html><b ody><form action='#' name='myform' method='post'>< TEXTAREA rows='2' cols='20' name='ta'></TEXTAREA><br><I NPUT type='button' value='save' onclick='javasc ript:alert1(thi s.form);'><INPU T type='button' value='cancel' onclick='javasc ript:window.clo se();'></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]
    Last edited by gits; Mar 19 '08, 06:22 PM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Originally posted by destiny007
    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?

    Comment

    Working...