Copy Function Does Not Work With Right Click Menu

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
pentace
Beginner
Beginner
Posts: 2
Joined: Fri Mar 16, 2007 10:27 pm

Copy Function Does Not Work With Right Click Menu

Post by pentace »

I have this code that basically duplicates the right click and copy feature or ctrl +c and it works fine if it is anything on the page calling the function, but if i use a menu like the right click menu it calls the function but nothing copies... can anyone help?

Code: Select all

<script>
function Dupme() {
     // Get the selected Html source of the window object
     // where the context menu item was executed
     var selectedHtml=(document.selection.createRange()).htmlText;
     // Set the clipboard with selected HTML, if there is any
     if(selectedHtml!= "")
         window.clipboardData.setData("Text",selectedHtml);}


</script>
<input type=button value="Copy Selected Text" onclick=Dupme()>
test text to copy
This code works fine but if i take out the button and use a menu with this... nothing copies

Code: Select all

aI("separatorsize=1;text=Copy Selected;url=javascript:Dupme();");

http://milonic.com/menusample27.php Here is the menu im trying to add it into
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Hi,

The problem is that you must set that aI string to type=html;

Code: Select all

aI("separatorsize=1;text=Copy Selected;url=javascript:Dupme();type=html;");
You do know that this isn't going to work in other than IE? For example, in FF [an older version] it does copy to clipboard but it copies the aI string, not any text you highlight. I believe that's going to be an issue, since the copy to clipboard I think is IE only. Here's a post which kind of say it's not going to happen, since in reality the right click and get a context menu with copy on it is not part of the web page but part of the operating system, and for security reasons FF and Moz don't allow that kind of access.

viewtopic. ... 0065#30065

Info on allowing access for FF which I found

http://kb.mozillazine.org/Granting_Java ... _clipboard

and one site which says they have a function that works across the browsers, something about having to sign the js. The page is hard to read since it is dark and seems to have dark green text in parts of the 'code' examples, but I highlighted the page which makes it look white and could read it :) I thought it might give you some help if you know anything about js, which I don't.

http://www.krikkit.net/howto_javascript ... board.html

Hope this helps

Ruth
pentace
Beginner
Beginner
Posts: 2
Joined: Fri Mar 16, 2007 10:27 pm

Thanks

Post by pentace »

Thanks... it worked great.. I cant beleive it was something that simple.
Post Reply