javascript教程複製指定內容保存到剪切板代碼
html代碼
<input type="text" id="testinput" name="testinput" value="4234324234" />
<div id="buttonbox">
<button onclick="copy('testinput')">copy</button>
</div> flash代碼
on (release) {
import flash.external.externalinterface;
var inputtext = externalinterface.call('flashcopy');
system.setclipboard(inputtext);
externalinterface.call('flashcopyback');
_root.bobotext.text = inputtext;
} js代碼
<script>
function $(id){
return document.getelementbyid(id);
}
function copy(){//ie6
var value = $('testinput').value;
window.clipboarddata.cleardata();
window.clipboarddata.setdata("text", value);
alert('複製成功! ');
}
function flashcopy(){//firefox .......
return $('testinput').value;
}
function flashcopyback(){
alert('複製成功! ');
}
if("v" != "v"){//如果不是ie時,就用flash的方式複製
$('buttonbox').innerhtml = '<embed src="111.swf" width="48" heig ht="23" quality="high" pluginspage="HTTP://www.macromedia.com/go/getflashplayer" type="application/ x-shockwave-flash"></embed>';
}
</script>
if (window.xmlHTTPrequest){//如果不是ie時,就用flash的方式複製
$('buttonbox').innerhtml = '<embed src="flashcopy.swf" width="48"
height="23" quality="high"
pluginspage="HTTP://www.macromedia.com/go/getflashplayer"
type=" application/x-shockwave-flash"></embed>';
}