我已经jQuery.terminal嵌入我的网页上,我能够通过键入发送命令到它。我正在处理的脚本中有许多console.log和console.dir命令,我希望终端也输出这些命令,但不会输出。
我当时在想,这可能是解决SO问题的人所做的事情。通过覆盖console.log:
我想用jQuery.terminal做这样的事情
console.log=function(str){term.echo(str);};
我看不到它应该如何工作。由于我无法通过Chrome控制台访问终端(找不到执行回显的部分)。
var log;
$('#term').terminal(function(command,term){
if(command!==''){
try{
var result=window.eval(command);
if(result!==undefined){
term.echo(new String(result));
}}
catch(e){
term.error(new String(e));
}}
else{
term.echo('');
}},{
welcome:false,
height:200,
prompt:'> ',
onInit:function(term){
log=term; // now log should reference to term
alert('hello'); // I don't see this alert
}});
console.log('hello'); //only the browsers own console shows this message
然后,如果我手动输入Chrome控制台:
log.echo('hi'); // Cannot read property 'echo' of undefined
我看到有一个$ .terminal对象,但是,我没有看到访问此以太币回波的方法。我如何正确执行此操作,或者开发人员是否已设置一种确定的方法来完成我所缺少的操作?我不想弄乱逗号分隔的日志或目录对象。
插件返回终端实例,因此您应该执行以下操作:
var term = $('#term').terminal(function(command,term) {
...
}, {...});
console.log = function(str){ term.echo(str); };
另外,如果要访问当前终端,可以使用:
var term = $.terminal.active();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句