Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-17-2008, 11:52 AM   PM User | #1
jeffshead
New Coder

 
Join Date: Oct 2008
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
jeffshead is an unknown quantity at this point
Newbie needing help with this script

Can someone help me, plz???

I want to make the following changes to the script below, but after countless hours of googling,testing,googling, I cannot get it to work.

Here's what I'm trying to do:

1. Use the script 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
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>
jeffshead is offline   Reply With Quote
Old 10-19-2008, 03:35 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Have you found these? If not, see if these help.
http://www.dynamic-tools.net/toolbox/copyToClipboard/
http://www.htmlgoodies.com/beyond/ja...le.php/3458851
http://lab.artlung.com/copy-to-clipboard-javascript/
jmrker is offline   Reply With Quote
Old 10-19-2008, 03:44 AM   PM User | #3
jeffshead
New Coder

 
Join Date: Oct 2008
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
jeffshead is an unknown quantity at this point
Yeah, I came across those too. They don't work with FF default security settings and IE throws the "do you want to allow access to the clipboard" alert.

What makes the script, I posted, unique is the fact that it uses a SWF file to pass the text. It is the only one that works with IE and FF without any browser alerts or warning messages.

Anyone else?
jeffshead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 PM.


Advertisement
Log in to turn off these ads.