2

I have some problems with LMC Button because of the way it is coded.

ShowLMCButton('Copied Text Here');

An image "Copy" is loaded when the page loads, with the words "Copied Text Here" being copied to clipboard when the image is clicked on.

If I do this:

var text = "New Text";
ShowLMCButton(text);

The words "New Text" is copied to the clip no problem, but the variable text have to be there on page load. There is no way I can change the words.

This is the ShowLMCButton function

function ShowLMCButton(cliptext, capt, js, furl)
{
 var params = 'txt=' + encodeURIComponent(cliptext); 
 if (!isNotEmpty(furl)) { furl = "clippy/lmcbutton.swf"; }
 if (isNotEmpty(capt)) { params += '&capt=' + capt; }
 if (isNotEmpty(js)) { params += '&js=' + js; }

document.write('<object width="40" height="20">');
document.write(' <param name="movie" value="' + furl + '">');
document.write(' <PARAM NAME=FlashVars VALUE="' + params + '">');
document.write(' <embed src="' + furl + '" flashvars="' + params + '"  width="40" height="20"></embed>');
document.write('</object>');

//alert('file: ' + furl + ' Params: ' + params); // debug
}

How can I copy text that I type in a textarea/input textfield?

Here is the demo of the button

4

2 回答 2

1

我刚才能够完成这项工作。

您只需要编辑 ShowLMCButton 函数,替换 'document.write'

var flash_movie = '<object id="copy-btn" width="80" height="20">';
flash_movie += ' <param name="movie" value="' + furl + '">';
flash_movie +=' <PARAM NAME=FlashVars VALUE="' + params + '">';
flash_movie +=' <PARAM NAME=wmode VALUE="transparent"><param name="scale" value="exactfit" />';
flash_movie +=' <embed id="flash-copy-btn" src="' + furl + '" flashvars="' + params + '" scale="exactfit" WMODE="transparent" width="90" height="20"></embed>';
flash_movie +='</object>';

return flash_movie;

有了这个,您现在可以在要复制的文本更改后调用 ShowLMCButton。

您可能需要一个附加功能,例如

function update_me(custom_text){
    document.getElementById('binfocopytext').innerHTML=custom_text;
        document.getElementById('copy-binfo2').innerHTML=ShowLMCButton(document.getElementById('binfocopytext').innerHTML,'','','lmcbutton_copytoclipboard/lmcbutton.swf');             
}

并在例如 onclick 上调用它:

<b onclick="update_me('updated text');">whatever</b>
于 2013-07-26T21:37:19.847 回答
-2

您可以通过以下方式获取文本字段/文本字段

ShowLMCButton(document.getElementById('id of the element').value,'copy','',path to lmcbutton.swf);
于 2013-03-01T05:44:35.907 回答