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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cross browser flashcopier JavaScript

    I found this wonderful cross browser copy to clipboard script, but because I am new to JavaScript, I cannot figure out how to edit it to suite my needs.

    I sent a few e-mails to the author, but never received a reply.

    Can someone help me with the changes?

    Here is the URL:
    http://www.rodsdot.com/ee/cross_brow...er_message.asp

    Here is the code:

    Code:
    <html>
    
    <head>
    <link rel="stylesheet" type="text/css" href="ee.css">
    <script type="text/javascript" src="events.js"></script>
    <script type="text/javascript" src="htmlDecode.js"></script>
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">
    <!--
    var mousex;
    var mousey;
    
    function doClick(e) {
        	if (e) { 
    		if (e.pageX || e.pageY) {
    			mousex = e.pageX;
    			mousey = e.pageY;
    		}else if (e.clientX || e.clientY) {
    			mousex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
    			mousey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    		}  
    	}
    	
      	var theCode = document.getElementById(this.id+'Pre').innerHTML;
      	theCode = htmlDecode(theCode);
    	copy(theCode);
    	openCopyMessage();
    }
    
    function copy(text2copy) {
    	if (window.clipboardData) {
    /* Remove comment to use text copy for windows
    	
    window.clipboardData.setData("Text",text2copy);
    	}else{
    */
    		var so = new SWFObject('_clipboard.swf', 'copy_contents', '0', '0', '4');
    		so.addVariable('clipboard', escape(text2copy));
    		so.write('flashcontent');
    	}
    }
    
    function openCopyMessage() {
    	document.getElementById('copyPopOver').style.display='block';
    	document.getElementById('copyPopOver').style.top=mousey+'px';
    	document.getElementById('copyPopOver').style.left=mousex+'px';
    }
    
    function closeCopyMessage() {
    	document.getElementById('copyPopOver').style.display='none';
    	return false;
    }
    
    function init() {
    	if (window.clipboardData) {
    		document.getElementById('flashcontent').innerHTML='';
    		document.getElementById('flashcontent').style.display='none';
    	}else{
    		var so = new SWFObject('_clipboard.swf', 'copy_contents', '0', '0', '4');
    		so.addVariable('clipboard', 'init');
    		so.write('flashcontent');
    	}
    	if ((document.getElementById('flashcontent').innerHTML.substr(0,6)=='<embed') || (document.getElementById('flashcontent').innerHTML.substr(0,6)=='')) {
    		addEvent(document.getElementById('theCode'), 'click', doClick);
    	}
    }
    //-->
    </script>
    <style type="text/css">
    <!--
    #copyPopOver {
    	position:absolute;
    	display:none;
    	width:350px;
    	color:#000000;
    	border:2px solid #FF9900;
    	padding:5px;
    	background-color:#FFE6BF;
    	top:-400px;
    	left:-400px;
    }
    
    #copyPopOver a {
    	color:#FF9900;
    }
    
    #copyPopOver a:hover {
    	color:#000000;
    	background-color:#FF9900;
    }
    -->
    </style>
    </head>
    
    <body>
    <div id="flashcontent">
      <br>You will need Flash Player or Internet Explorer to copy code from this page.<br><br>
    </div>
    <noscript><p>You need JavaScript to view this example.</p></noscript>
    <p>&nbsp;</p>
    <div class="code" id="theCode">
      <pre id="theCodePre">your example code</pre>
    </div>
    <div id="copyPopOver">This code is © 2005-2007 Roderick Divilbiss.<p><strong>The code was copied to your clip board.</strong></p>
    	<p>Except where otherwise noted, this site, all content, and all source code and markup is licensed under a Creative Commons License <a rel="license" href="http://creativecommons.org/licenses/by-nc/2.0/">Creative Commons License</a>.&nbsp; Any code based or inspired by this code requires that code to also be available under the same license and requires attribution.</p>
    	<p>Please read and honor the <a href="http://www.rodsdot.com/termsofuse.asp">Terms Of Use</a> to use this code.</p>
    	<p>[<a href="#" onClick="closeCopyMessage(); return false;">close message</a>]
    </div>
    <script type="text/javascript">init()</script>
    </body>
    
    </html>
    Unfortunatly, I cannot use the script for my project unless the following changes are made:

    1. Use with multiple textarea tags so the user can copy the full text from each box.
    2. Have a "Copy to clipborad" button for each textarea box.

    Optional:
    1. Make the pop-up fade away after a set time instead of having to click on the close link.

    I've been "googling" and "playing" with the script for days, but can't figure it out. Any help would be most appreciated

  • #2
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry *** NOTICE *** Flash Player 10

    Flash Player 10 updates went out today.

    This script will no longer allow the traditional clipboard access.

    For more info, see the Adobe security article: http://www.adobe.com/devnet/flashpla...hanges_02.html

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by unicron View Post
    Flash Player 10 updates went out today.

    This script will no longer allow the traditional clipboard access.

    For more info, see the Adobe security article: http://www.adobe.com/devnet/flashpla...hanges_02.html
    Darn it!!!! Your post is appreciated though.

    Does that mean the script is totally useless even if it were tweaked to include a JavaScript "copy to clipboard" button? I ask because here is a quote from the Adobe page:

    "Setting the Clipboard will now have to be invoked through a button, keyboard shortcut, or some other event initiated by the user."

    Are they talking about some sort of a Flash button or a JavaScript button? If a JavaScript button were to be used, would an alert be displayed?

  • #4
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The script is still functional as of today 7-14-2010

    I regret that I missed any e-mails you may have sent. In October 08 I was battling cancer and was not active on-line. Unicron's post regarding Flash 10 do not apply to this object. It was not broken by Flash 10 although other similar methods were.

    This reply may be too late for your project but might be useful for others who happen to read this thread. You may in fact use multiple clipboard copy objects on one page. Also, as of Flash 10.5 this still works.

    A multiple clipboard object example page is here: http://www.rodsdot.com/demo/multiple...py_buttons.asp

    And a practical example: http://www.rodsdot.com/asp/shoeOrderForm.asp

    Happy coding,
    Rod
    Last edited by rdivilbiss; 07-14-2010 at 09:47 PM.


  •  

    Posting Permissions

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