javascript的Run,Copy,Save Code功能

function copyCode(obj) {
 var rng = document.body.createTextRange();
 rng.moveToElementText(obj);
 rng.scrollIntoView();
 rng.select();
 rng.execCommand("Copy");
 rng.collapse(false);
}
function runCode(obj) {
 var winname = window.open('', "_blank", '');
 winname.document.open('text/html', 'replace');
 winname.document.writeln(obj.value);
 winname.document.close();
}
function saveCode(obj) {
 var winname = window.open('', '_blank', 'top=10000');
 winname.document.open('text/html', 'replace');
 winname.document.writeln(obj.value);
 winname.document.execCommand('saveas','','code.htm');
 winname.close();
}

转自: http://blog.csdn.net/oicqren/archive/2004/11/05/168691.aspx

发表评论

返回顶部