0
我有jQuery.terminal嵌入在我的頁面上,我可以通過輸入命令發送命令。在我正在處理的腳本中有很多console.log和console.dir命令,我希望終端也輸出這些命令,但它不會。全局訪問回聲(jquery終端)
我在想這可能就像這個SO問題上的人一樣;通過重寫的console.log:
Embed JS Console within website
我願做這樣的事情與jQuery.terminal
console.log=function(str){term.echo(str);};
我看不出它是如何想的工作。由於我無法通過Chromes控制檯訪問終端(我無法找到執行回顯的部分)。
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
然後,如果我手動鍵入鉻合金控制檯:
log.echo('hi'); // Cannot read property 'echo' of undefined
我看到有一個$ .terminal對象,但我不明白的方式從該醚訪問回聲。我該如何正確執行此操作,或者確實有開發人員設定的方式來執行此操作,以致於我失蹤?我不想搞亂逗號分隔的日誌或目錄對象。