function reportError(msg,url,line) {
var str = "You have found an error as below: \n\n";
str += "Err: " + msg + " on line: " + line;
alert(str);
return true;
}
window.onerror = reportError;
document.onkeydown = function() {
if(event.ctrlKey){
switch(event.keyCode) {
case 82: //r
runcode();
break;
case 83: //s
savecode();
break;
case 71: //g
goto(prompt('Please input the line number', '1'));
break;
case 65: //a
document.execCommand("SelectAll");
break;
case 67: //c
document.execCommand("Copy");
break;
case 88: //x
document.execCommand("Cut");
break;
case 86: //v
document.execCommand("Paste");
break;
case 90: //z
document.execCommand("Undo");
break;
case 89: //y
document.execCommand("Redo");
break;
default:
break;
}
event.keyCode = 0;
event.returnValue = false;
}
return;
}
function show_ln(){
var txt_ln = document.getElementById('txt_ln');
var txt_main = document.getElementById('txt_main');
txt_ln.scrollTop = txt_main.scrollTop;
while(txt_ln.scrollTop != txt_main.scrollTop) {
txt_ln.value += (i++) + '\n';
txt_ln.scrollTop = txt_main.scrollTop;
}
return;
}
function editTab(){
var code, sel, tmp, r;
event.returnValue = false;
sel =event.srcElement.document.selection.createRange();
r = event.srcElement.createTextRange();
function runcode() {
var str = document.getElementById("txt_main").value;
var code_win = window.open('about:blank');
code_win.document.open();
code_win.document.writeln("<script>");
code_win.document.writeln("function reportError(msg,url,line){\nline-=14;\nvar str='You have found an error as below: \\n\\n';\nstr+='Err: '+msg+' on line: '+(line);\nalert(str);\nopener.goto(line);\nopener.focus();\nwindow.onerror=null;\nsetTimeout('self.close()',10);\nreturn true;\n}");
code_win.document.writeln("window.onerror = reportError;");
code_win.document.writeln("<\/script>");
code_win.document.writeln(str);
code_win.document.close();
return;
}
function savecode() {
var str = document.getElementById("txt_main").value;
var code_win = window.open('about:blank','_blank','top=10000');
code_win.document.open();
code_win.document.writeln(str);
code_win.document.close();
code_win.document.execCommand('saveas','','code.html');
code_win.close();
return;
}
function runCode() {
var code=source.value;
var newwin=window.open('','RunCode','');
newwin.opener = null
newwin.document.write(code);
newwin.document.close();
}
function inserttag(wantag){
document.frm.source.value+=wantag;
}
function keydown() {
if((event.ctrlKey)&&(event.keyCode==10)) {
runCode();
} else if ((event.ctrlKey)&&(event.keyCode==49)) {
alert();
}
}
var tbl="<TABLE id=tbl cellSpacing=1 cellPadding=1 border=1>\n<TBODY>\n<TR>\n<TD width=100>This is Line1</TD></TR>\n<TR>\n<TD width=100>This is Line2</TD></TR>\n<TR>\n<TD width=100>This is Line3</TD></TR>\n</TBODY>\n</TABLE>";
</script>
</head>
</body></textarea></center>
<br>
<p align=center><a href="JavaScript:source.focus();void(document.execCommand('paste',0,tbl));">Insert Table</a><input type=submit name="run" value=" R u n " onclick="runCode()"></p>