<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" >
function Preview(obj) {
var TestWin=window.open('','',''); //打开一个窗口并赋给变量TestWin。
TestWin.opener = null // 防止代码对论谈页面修改
TestWin.document.write(obj.value);//向这个打开的窗口中写入代码code这样就实现了运行代码功能。
TestWin.document.close();
}
//复制文本域代码
function copyCode(obj) {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
//另存文本域代码
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();
}
//收藏本页代码
function addBookmark(title,url) {
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
} else if( document.all ) {
window.external.AddFavorite(url,title);
} else if( window.opera && window.print ) {
return true;
}
}
</script>
</head>
<body>
<textarea id="code1" style="width: 560px; height: 200px">
放你想运行的代码
</textarea> <br />
<button onclick="Preview(code1)">运行代码</button><button onclick="copyCode(code1)">复制代码</button><button onclick="saveCode(code1)">另存代码</button><button onclick="addBookmark(document.title,location.href)">收藏本页</button>
</body>
</html>
posted on 2008-05-27 16:27
毒毒 阅读(366)
评论(1) 编辑 收藏