<script>
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_webtv = userAgent.indexOf('webtv') != -1;
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera && !is_saf && !is_webtv) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
function runCode(obj) {
var winname = window.open('', "_blank", '');
winname.document.open('text/html', 'replace');
winname.opener = null; // 防止代码对论谈页面修改
winname.document.write(obj.value);
winname.document.close();
}
function saveCode(obj) {
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.write(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}
function copycode(obj) {
if(is_ie && obj.style.display != 'none') {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
}
</script>
<textarea id=code cols=80 rows=15></textarea>
<br />
<input type="button" onclick="runCode(code)" value="运行代码" style="border:1px solid #B1B4CD;background:#696D81;color:#FFFFFF; padding-top:5px;">
<input type="button" onclick=copycode(code) style="border:1px solid #B1B4CD;background:#696D81;color:#FFFFFF; padding-top:5px;" value="复制代码">
<input type="button" onclick=saveCode(code) style="border:1px solid #B1B4CD;background:#696D81;color:#FFFFFF; padding-top:5px;" value="另存代码" >
提示:您可以先修改部分代码再运行
<br>