Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts

    displaying highlighted text from an inline page

    I have a short script which will instantly copy highlighted text on a page and have it display in a form button:

    <form name=theform>
    Selected text: <input type=text name=text value="">
    </form>

    It works well - here is the code:

    Code:
    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();
    
    document.theform.text.value = text;
    return true;
    }
    
    document.onmouseup = getActiveText;
    if (!document.all) document.captureEvents(Event.MOUSEUP);
    My problem is that I need to highlight text within an inline frame on the page, not on the page itself, and have it display in the form button.

    What should I alter in the script to make this happen? Am I asking the impossible; I don't think it would be if I knew how to reference the inline code page from this page.

    Thanks
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by tpeck View Post
    I have a short script which will instantly copy highlighted text on a page and have it display in a form button:


    My problem is that I need to highlight text within an inline frame on the page, not on the page itself, and have it display in the form button.

    What should I alter in the script to make this happen? Am I asking the impossible; I don't think it would be if I knew how to reference the inline code page from this page.
    You need to place the code inside the framed document (which must be on the same domain).
    Try this script, replacing the bold text with the name of the form and the element to receive the text.

    Code:
    <SCRIPT type='text/javascript'>
    
    function getActiveText(elem)
    {
     elem.value = (document.selection && document.selection.createRange) ?
                    document.selection.createRange().text : 
                     document.getSelection?
                      document.getSelection():
                       "";
     
     return true;
    }
    
    if(document.captureEvents)
     document.captureEvents(Event.MOUSEUP);
    document.onmouseup = function(){getActiveText( parent.document.forms.myFormName.elementName  );}
    
    </SCRIPT>

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Wonderful! Thanks so much. You have shown it's possible. I can follow some of the code you supplied.

    Now I have to take it a little further. I now know the text can be displayed from the inline to the parent page, but I need to display it to another frame.

    I tried substituting the frame name for "parent" in the code but no luck.

    I also have to do this three times on a page. Here is a demo (sorry about the colour scheme!):

    http://aapress.com.au/demo/hilite/hilite.html

    When I get this right, I have to duplicate the entire structure 1000 times, so it would be helpful if the code was only in one place instead of the three inline frames, but I don't think that is likely.

    At the moment, if I can just get the blue text to display in the blue textbox bottom of the page I'll be very happy.

    (I've left the working example you supplied on the top frame - to demonstrate that it works).

    Thanks again.
    Last edited by tpeck; 12-13-2006 at 05:42 AM.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #4
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by tpeck View Post
    I tried substituting the frame name for "parent" in the code but no luck.

    I also have to do this three times on a page. Here is a demo (sorry about the colour scheme!):

    http://aapress.com.au/demo/hilite/hilite.html

    When I get this right, I have to duplicate the entire structure 1000 times, so it would be helpful if the code was only in one place instead of the three inline frames, but I don't think that is likely.

    At the moment, if I can just get the blue text to display in the blue textbox bottom of the page I'll be very happy.

    (I've left the working example you supplied on the top frame - to demonstrate that it works).

    Thanks again.
    The form tags in the target document aren't closed.

    Use: parent.parent.main.document.forms.q2.hilite2

  • #5
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Now why didn't I think of that? (don't answer!)

    How you reference windows/frames accurately has always eluded me. I mean, I get the drift, but I can't get the full hang of it.

    I've updated the demo to include all your fixes, and it is a joy to behold.

    Many thanks indeed!

    Terry
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •