Jump to content

Copy Text to clipboard


Deanznet

Recommended Posts

Hey! i got a box text box that i want people to be able to click on and it copys the text.

 

I have something that i took from photobucket but still it just says it copied it but it dosent..

 

This is what i have.

 

<input readonly="readonly" class="input_field" onclick="javascript:highlight(this); copyToClipboard(this);"

 

 

 

function copyToClipboard(elt) {
var urlSwf = "/include/swf/_clipboard.swf";
var strMssgBoxId = "notifyTextCopied";
var eltNotify = null;

// Display Notifications
if((eltNotify = $(strMssgBoxId)) == null){
	// Attach the notification to the DOM
	var eltBody = document.getElementsByTagName('body').item(0);

	eltNotify = document.createElement('div');
	eltNotify.setAttribute('id', strMssgBoxId);
	eltNotify.style.display = 'none';

	eltNotify.innerHTML = 'Copied';

	eltBody.appendChild(eltNotify);
}
elt.onblur =
	function(e){
		Element.hide(eltNotify);
		return true;
	}

var z = Position.cumulativeOffset(elt);
var x = z[0];
var y = z[1];

Element.show(eltNotify);

if(navigator.appName == 'Microsoft Internet Explorer'){
	if(x < 100){
		eltNotify.style.left = (x + (elt.offsetWidth - 23)) + 'px';
	}
	else{
		eltNotify.style.left = (x - (eltNotify.offsetWidth + 2)) + 'px';
	}
}
else{
	if(x < 100){
		eltNotify.style.left = (x + (elt.offsetWidth + 3)) + 'px';
	}
	else{
		eltNotify.style.left = (x - (eltNotify.offsetWidth + 2)) + 'px';
	}
}

eltNotify.style.top = y + 'px';

var xEffect = Effect.Fade(eltNotify, { fps: 75, from: 1.9, to: 0.0, duration: 1.0, queue: 'front' } );
window.status = 'Copied text to clipboard';

// Copy the text inside the text box to the user's clipboard
var flashcopier = 'flashcopier';
if(!$(flashcopier)){
	var divholder = document.createElement('div');
	divholder.id = flashcopier;
	document.body.appendChild(divholder);
}

$(flashcopier).innerHTML = '';
var divinfo = '<embed src="' + urlSwf + '" FlashVars="clipboard='+escape(elt.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
$(flashcopier).innerHTML = divinfo;

elt.select();

return true;
}

Link to comment
Share on other sites

Download the swf file from here:

http://beta.tzfiles.com/incl/javascript/

 

and use this:

 

// JavaScript Document
// field = field ID
function highlight(field) {
    field.focus();
    field.select();
    var urlSwf = "/incl/javascript/copy.swf";

    window.status = 'Copied text to clipboard';

    // Copy the text inside the text box to the user's clipboard
    var flashcopier = 'flashcopier';
    var divholder = document.createElement('div');
    divholder.id = flashcopier;
    document.body.appendChild(divholder);

    divholder.innerHTML = '';
    var divinfo = '<embed src="' + urlSwf + '" FlashVars="clipboard='+escape(field.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    divholder.innerHTML = divinfo;
    return false;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.