【问题标题】:Load raw link contents into terminal将原始链接内容加载到终端
【发布时间】:2018-10-18 03:19:33
【问题描述】:

我正在使用 raw 属性将格式化数据从 url 获取到终端,就像这样

$(function() {
var save_state = [];
var terminal = $('#term').terminal(function(command, term) {

        term.pause();

        url = ...;
        $.get(url, function(result) {
            term.echo(result, {raw:true}).resume();

        });

}, { prompt: '>>', name: 'test', outputLimit: 1000 });


});

我想知道,我如何获得它,所以当点击结果中的链接时,它们会将数据加载到终端中,就像加载命令数据一样,而不是打开一个新的浏览器选项卡?

谢谢!

【问题讨论】:

    标签: jquery-terminal


    【解决方案1】:

    如果您使用的命令包含 URL 或 URI(例如 get foo.htmlget https://example.com),您可以使用:

    terminal.on('click', '.terminal-output > div:not(.exception) a', function() {
       // if you don't use `true` it will show the command like if you type it
       // instead of `get` you can use any command you have that will
       // fetch the url and display it on the terminal
       terminal.exec('get ' + $(this).attr('href'), true);
       return false; // prevent following the link
    });
    

    如果您有不同的逻辑来显示 url,您可能需要在 click 事件处理程序中从解释器中提取代码。

    terminal.on('click', '.terminal-output > div:not(.exception) a', function() {
        // duplicated code from your interpreter
        term.pause();
        var url = $(this).attr('href');
        $.get(url, function(result) {
            term.echo(result, {raw:true}).resume();
        });
        return false;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 2016-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多