Solved

document.getSelection in Frames

Posted on 1998-09-24
3
605 Views
Last Modified: 2012-08-14
Can someone make the following script work in frames?  I need the selection from one frame to appear in the text area  in another frame.  In other words, when I select the text in frame 1, the selection will automatically appear in the text box in frame 2.
<HTML>
<BODY>
<P>text text</P>
<P>something else</P>
<P>More text</P>
<FORM NAME="aForm">
<A NAME="A"></A><FONT FACE="Arial,Helvetica" SIZE=-1>Part Name:&nbsp;</FONT>&nbsp;<INPUT TYPE=TEXT NAME="aName" SIZE=50>&nbsp;

</FORM>
</BODY>
</HTML>

<SCRIPT LANGUAGE="JavaScript">
        <!--

        function display() {
          if (document.getSelection) {
            var str = document.getSelection();
            if (window.RegExp) {
              var regstr = unescape("%20%20%20%20%20");
              var regexp = new RegExp(regstr, "g");
              str = str.replace(regexp, "");
            }
          } else if (document.selection && document.selection.createRange) {
            var range = document.selection.createRange();
            var str = range.text;
          } else {
            var str = "Sorry, this is not possible with your browser.";
          }
          document.aForm.aName.value = str;
        }

        if (window.Event)
          document.captureEvents(Event.MOUSEUP);
        document.onmouseup = display;

        // -->
        </SCRIPT>

I got it from webreference.com.

Kurt
0
Comment
Question by:kmartin7
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
martinag earned 200 total points
Comment Utility
Index.htm
------
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<FRAMESET COLS="50%,*">
<FRAME SRC="left.htm">
<FRAME SRC="right.htm" NAME="formFrame">
</FRAMESET>
</HEAD>
<NOFRAMES>
<BODY>
Sorry, your browser does not support frames.
</BODY>
</NOFRAMES>
</HTML>

left.htm
------

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function display() {
  if (document.getSelection) {
    var str = document.getSelection();
    if (window.RegExp) {
      var regstr = unescape("%20%20%20%20%20");
      var regexp = new RegExp(regstr, "g");
      str = str.replace(regexp, "");
    }
  }
  else if (document.selection && document.selection.createRange) {
    var range = document.selection.createRange();
    var str = range.text;
  }
  else {
    var str = "Sorry, this is not possible with your browser.";
  }
  parent.formFrame.document.aForm.aName.value = str;
}

if (window.Event)
document.captureEvents(Event.MOUSEUP);
document.onmouseup = display;

// -->
</SCRIPT>
</HEAD>
<BODY>
<P>text text</P>
<P>something else</P>
<P>More text</P>
</BODY>
</HTML>

right.htm
------
<HTML>
<BODY>
<FORM NAME="aForm">
<A NAME="A"></A><FONT FACE="Arial,Helvetica" SIZE=-1>Part   Name:&nbsp;</FONT>&nbsp;<INPUT TYPE=TEXT NAME="aName" SIZE=50>&nbsp;
</FORM>
</BODY>

Martin
0
 
LVL 11

Author Comment

by:kmartin7
Comment Utility
parent.formFrame

Boy, do I feel stupid.  Here's the 200 points, Martin.


Kurt
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
Thank you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now