Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:39

Menu Item for "Copy Command"


Poster: gxgolfer
Dated: Friday July 1 2005 - 4:33:13 BST

Is there AI code to list the "copy command" as an option? I want to add the "copy" command into the right click menu.

Thanks in Advance!


Poster: Ruth
Dated: Friday July 1 2005 - 7:48:16 BST

Hi,

I'm assuming you mean the copyToClipboard function. As far as I know you'd just put in the call for the function to do that. So, first you'd have to create/put the function in the menu_data.js. For example, in the dynamic context menu demo example, you have a different context menu when you right click on a link as opposed to just on the page someplace. If you open the menu_data.js file you'll see a function up in the top area
Code:
function mm_setUrlToOpen()
{
  _mi[_itemRef][2] = contextObject.href;
  itemOff(_itemRef);
  itemOn(_itemRef);
}


If you look down at the 2nd menu, the contextlink menu in the aI string for Open you'll see the call for that function:
Code:
aI("text=Open;onfunction=mm_setUrlToOpen();");
There is also a call for that function in the aI string for Open in a New Window

You can check the demo for the IE FILTERS and in the mm_filters.js file there is a copyToClipboard function. It works on the form button.

Here are the links I found on copyToClipBoard functions:
beyond html This applies a function to text identified through a span ID.

This one has a 'triple' function, one that checks to see if the function would 'work' with the browser, then on click it highlights the text clicked and copies it to clipboard. I'm not sure you could use this one at all since you'd not have text clicked, but maybe right clicking the text would apply it.

This one is the one that says it will work in Mozilla/Netscape and IE.

Now, I am not a code person, but I'd think you'd have to have a particular thing you wanted to copy so that the link would have to be applied to that thing. I'm not sure how you would do that. Also, I'm pretty sure that it only works in IE, though I've found that link that is supposed to have a function that will work in Mozilla/Netscape [which probably means Firefox, also] and IE. It does seem to work, but since I don't know functions I can only get it to copy the words meintext which are the words in the function. But, as to applying any of the functions to a particular thing, I don't know how to do that. The one from htmlgoodies, if you were to use that, you would place the following in the top part of the menu_data.js file below the mm_setUrlToOpen function:

Code:
function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}


Then in the aI string you'd have this
Code:
aI("text=Copy;onfunction=ClipBoard();");
Now so far you've got the function, have placed the call for it in the right click menu, but you need it to copy something. So, on the page [with this function] you'd have to have a span tag with the ID of "copytext" around the text you want to copy.
Code:
<SPAN ID="copytext">text to be copied</SPAN>
and you would also need a place for the copied text to 'wait' while it's being pasted, this one uses a hidden text area on the page.
Code:
<TEXTAREA ID="holdtext" STYLE="display:none;">


I tested that and it works. I actually put the span tags around the whole page. On clicking the Copy item in the right click menu it copied all the text on the page.

So, what exactly do you want to copy? [excuse any typos, it's late here]

Ruth


Poster: gxgolfer
Dated: Friday July 1 2005 - 18:41:19 BST

I want to be able to highlight text and then do a right click copy. I figured if open in new window works, then there must be code for other normal right click functions like copy and paste. Is there such a resource for AI statements?


Poster: Ruth
Dated: Friday July 1 2005 - 20:08:59 BST

The reason open in a new window works is because the aI string uses the target=_new parameter.
Code:
aI("text=Open in a New Window;target='new';separatorsize=1;onfunction=mm_setUrlToOpen();");


Now the mm_setUrlToOpen function, I guess, would have something to do with reading the actual link url and 'putting' that into the click so it goes to the right page.

As to having something in the menu some parameter that would highlight and then copy text, how would you know which text the person wanted to highlight? That is usually done manually by clicking the left button on the mouse, holding it, and dragging it over text. But, you should be able to use one of the functions to 'copy' manually highlighted text. That is the person drags the mouse over and highlights text and then right clicks and gets the copy command. I will try some more searching on the web and see if I can find a function out there that will 'copytoclipboard' manually highlighted text. If I find one I'll post back, then you would use it just like the mm_setUrlToOpen function is used in the Open and Open in a new window aI strings.

Ruth

Ruth


Poster: Ruth
Dated: Saturday July 2 2005 - 0:53:55 BST

Hi gx,

[smacking head] I finally figured out what you were saying! :oops: You want the normal right click copy and paste as items in the menu. Is that correct? If so, it will still take finding out whatever that command is and I believe it will have to be made into a function. So, I just wanted to let you know that things finally got through my thick skull. Sorry for the misunderstanding and I'm sure the frustration on your part.

Ruth


Poster: gxgolfer
Dated: Saturday July 2 2005 - 2:44:48 BST

Ruth,

Thank you for all your help as this really is a great forum with people like you to help support these scripts. You summed up what I'm looking for.

Thanks much.


Poster: Ruth
Dated: Monday July 4 2005 - 17:28:29 BST

Hi gx,

I just thought I'd let you know that I think you're going to be out of luck on this. I've posted to Andy for one last authority on it, but as far as I can find out, the copy command to which you are referring is 'proprietary' to the browsers and not something you can make into a function. You can make functions as I noted where the person can copy the whole page, or specific parts, based on using IDs of some kind, but not where the function will read what the person has manually highlighted with the mouse. That highlight and right click copy is some kind of 'command' written into the various browsers' programming, and not necessarily the same in every browser. When I hear from Andy, I"ll let you know, but my feeling is it's going to be 'not possible' or at the least 'possible but requiring very involved programming to do it. Sorry :cry: I hope I'm wrong on this because I'd like that, too. That would be really neat, not having to disable that menu in order to copy something.

Ruth


Poster: Ruth
Dated: Wednesday July 6 2005 - 13:11:58 BST

Hi gx,

Well, I was right. Andy says it might be possible, but the function would be very involved and would have to be browser specific. I think that means having to get into the browser [or maybe it's the operating system] programming to figure out how that copy/paste command in the normal context menu works.

Also, given what I found out about Mozilla, I think you'd have to do something like the function I did find that works in Mozilla, which has to do with signatures, like are put into java applets [don't really know what that is, but it's something to do with security.

Just wanted to let you know.