Javascript:
var
sPop
=
null
;
var postSubmited = false ;
var smdiv = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf( ' webtv ' ) != - 1 ;
var is_kon = userAgent.indexOf( ' konqueror ' ) != - 1 ;
var is_mac = userAgent.indexOf( ' mac ' ) != - 1 ;
var is_saf = userAgent.indexOf( ' applewebkit ' ) != - 1 || navigator.vendor == ' Apple Computer, Inc. ' ;
var is_opera = userAgent.indexOf( ' opera ' ) != - 1 && opera.version();
var is_moz = (navigator.product == ' Gecko ' && ! is_saf) && userAgent.substr(userAgent.indexOf( ' firefox ' ) + 8 , 3 );
var is_ns = userAgent.indexOf( ' compatible ' ) == - 1 && userAgent.indexOf( ' mozilla ' ) != - 1 && ! is_opera && ! is_webtv && ! is_saf;
var is_ie = (userAgent.indexOf( ' msie ' ) != - 1 && ! is_opera && ! is_saf && ! is_webtv) && userAgent.substr(userAgent.indexOf( ' msie ' ) + 5 , 3 );
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);
}
}
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();
}
var postSubmited = false ;
var smdiv = new Array();
var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf( ' webtv ' ) != - 1 ;
var is_kon = userAgent.indexOf( ' konqueror ' ) != - 1 ;
var is_mac = userAgent.indexOf( ' mac ' ) != - 1 ;
var is_saf = userAgent.indexOf( ' applewebkit ' ) != - 1 || navigator.vendor == ' Apple Computer, Inc. ' ;
var is_opera = userAgent.indexOf( ' opera ' ) != - 1 && opera.version();
var is_moz = (navigator.product == ' Gecko ' && ! is_saf) && userAgent.substr(userAgent.indexOf( ' firefox ' ) + 8 , 3 );
var is_ns = userAgent.indexOf( ' compatible ' ) == - 1 && userAgent.indexOf( ' mozilla ' ) != - 1 && ! is_opera && ! is_webtv && ! is_saf;
var is_ie = (userAgent.indexOf( ' msie ' ) != - 1 && ! is_opera && ! is_saf && ! is_webtv) && userAgent.substr(userAgent.indexOf( ' msie ' ) + 5 , 3 );
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);
}
}
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();
}
Html:
<
textarea
name
="runcode0"
rows
="12"
cols
="95"
>
< div style= " float:left; width:600px; height:200px; background:red ">< /div >
< div style= " float:left; width:600px; height:200px; background:black ">< /div >
</ textarea >
< br >
< input type ="button" value ="运行代码" onclick ="runCode(runcode0)" >
< input type ="button" value ="复制代码" onclick ="copycode(runcode0)" >
< input type ="button" value ="另存代码" onclick ="saveCode(runcode0)" >
< div style= " float:left; width:600px; height:200px; background:red ">< /div >
< div style= " float:left; width:600px; height:200px; background:black ">< /div >
</ textarea >
< br >
< input type ="button" value ="运行代码" onclick ="runCode(runcode0)" >
< input type ="button" value ="复制代码" onclick ="copycode(runcode0)" >
< input type ="button" value ="另存代码" onclick ="saveCode(runcode0)" >