Solved

cut copy paste

Posted on 2004-10-06
5
737 Views
Last Modified: 2008-02-01
oh and first thing: only needs to work in ie

hey a while back i was working on something for my web word processor. i thought i'd give it another go.  

i got the context menu to work but i was never able to get cut copy and paste to work in it.

i was just losing the ranges and/or selections.  i think what is going to have to be done is everytime a selection is made it remembers it right here. if another selection is made then it just overwrites that variable.  i don't know. ranges and selections aren't my strong point.

heres some code.  

my context menu: and iframe that goes behind it

<IFRAME id="ContextIFrame" style="Z-INDEX: 106; LEFT: 312px; VISIBILITY: hidden; WIDTH: 60px; POSITION: absolute; TOP: 152px; HEIGHT: 132px">

<DIV class="Context" id="ContextDiv" style="Z-INDEX: 107; LEFT: 392px; VISIBILITY: hidden; WIDTH: 60px; POSITION: absolute; TOP: 152px; HEIGHT: 132px">
                        <TABLE style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma">
                              <TR>
                                    <td onmouseover="SetRollOverClass(this,'ContextTDMouseOver');" onclick="WP_SelectAll('WordProcessor1');"
                                          onmouseout="SetRollOutClass(this,'ContextTDMouseOut');">Select All</td>
                              </TR>
                              </TR>
                              <tr>
                                    <TD style="HEIGHT: 1px">
                                          <hr>
                                    </TD>
                              </tr>
                              <TR>
                                    <TD onmouseover="SetRollOverClass(this,'ContextTDMouseOver');" onclick="WP_Save('WordProcessor1');"
                                          onmouseout="SetRollOutClass(this,'ContextTDMouseOut');">Save</TD>
                              </TR>
                              <tr>
                                    <td onmouseover="SetRollOverClass(this,'ContextTDMouseOver');" onclick="WP_SaveAs('WordProcessor1');"
                                          onmouseout="SetRollOutClass(this,'ContextTDMouseOut');">Save As</td>
                              </tr>
                              </TR>
                              <tr>
                                    <TD>
                                          <hr>
                                    </TD>
                              </tr>
                              <tr>
                                    <TD onmouseover="SetRollOverClass(this,'ContextTDMouseOver');" onclick="WP_Print('WordProcessor1')"
                                          onmouseout="SetRollOutClass(this,'ContextTDMouseOut');">Print</TD>
                              </tr>
                              <TR>
                                    <TD onmouseover="SetRollOverClass(this,'ContextTDMouseOver');" onclick="WP_SpellChecker('WordProcessor1');"
                                          onmouseout="SetRollOutClass(this,'ContextTDMouseOut');">SpellCheck</TD>
                              </TR>
                        </TABLE>
                  </DIV>

javascript that shows and hides the context menu

function ShowMyContextMenu(div,iframe) {      
      var contextMenu= document.getElementById(div);
      var contextIFrame= document.getElementById(iframe);      
      var x;
      var y;
      if(event === null) {
            x= editor.event.clientX + contextOffsetX;
            y= editor.event.clientY + contextOffsetY;            
      } // end if
      else {
            x= event.clientX;
            y= event.clientY;
      } // end else            
      contextIFrame.style.left= x;
      contextIFrame.style.top= y;
      contextMenu.style.left= x;
      contextMenu.style.top= y;
      contextIFrame.style.visibility= "visible";
      contextMenu.style.visibility= "visible";            
} // end function

function HideContextMenu() {
      var context= document.getElementById("ContextDiv");
      if(context === null) {
            return;
      } // end if
      var contextFrame= document.getElementById("ContextIFrame");
      if(context.style.visibility == "visible") {
            context.style.visibility= "hidden";
            contextFrame.style.visibility= "hidden";                              
      } // end if
} // end function

my cut, copy, and paste functions just use the microsoft execCommands
0
Comment
Question by:das165227
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:riyasjef
ID: 12240649
Did u try this?
       
              function init()   //ONLOAD
             {
                  var obj=document.getElementById("ContextIFrame");
                  obj.document.designMode='On';
       
                 }

       function editor_cut()
       {
                 document.getElementById("ContextIFrame").focus();
          document.getElementById("ContextIFrame").document.execCommand('cut','',null);
       }

       function editor_copy()
       {
                document.getElementById("ContextIFrame").focus();
          document.getElementById("ContextIFrame").document.execCommand('cut','',null);
       }

Riyasjef
0
 
LVL 9

Accepted Solution

by:
riyasjef earned 500 total points
ID: 12240673
Sorry

function editor_copy()
      {
         document.getElementById("ContextIFrame").focus();
         document.getElementById("ContextIFrame").document.execCommand('copy','',null);
      }

function editor_paste()
      {
         document.getElementById("ContextIFrame").focus();
         document.getElementById("ContextIFrame").document.execCommand('paste','',null);
      }

0
 

Author Comment

by:das165227
ID: 12247969
i'm not sure that'll work.  i'll try it after i get done with the stuff i'm doing now but it looks like that code is going to end up copying whats in the context menu.  the main issue is keeping what is selected in the iframe selected while my context menu is open.  that oughta do it
0
 

Author Comment

by:das165227
ID: 12310177
sorry i just haven't had time to address this thing since i've been working on something else
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

910 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

20 Experts available now in Live!

Get 1:1 Help Now