如何从Chrome的Javascript控制台获取输入? [英] How to get input from Chrome's Javascript console?

查看:667
本文介绍了如何从Chrome的Javascript控制台获取输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式从Google Chrome的JavaScript控制台获取输入,类似于

Is there a way to programmatically get input from the Javascript Console of Google Chrome, similar to readline() in Firefox?

推荐答案

在Firefox中使用in-javascript> readline

这是一种接受输入的间接方法:

This is an indirect method of taking inputs:

在JavaScript中声明一个函数:

Declare a function in JavaScript:

function your_command_here()  {
    //code
}

由于Chrome的控制台基本上提供了与网页内容(如JavaScript变量,函数等)通讯的方法,因此将函数声明为可接收命令是一个选项。

As Chrome's console basically provides methods for communicating with the page's contents, like JavaScript variables, functions, etc., so declaring a function as a receivable command can be an option.

在控制台中,要提供输入,用户应输入:

your_command_here()

In the console, for providing input, the user shall type:
your_command_here()

另一种解决方法是:

声明一个函数:

Another workaround is:
Declare a function:

function command(var cmnd)  {
    switch(cmnd)  {
        case "command1":
            //code
        break;
    }
}


$ b < br>
命令(user's command here)

So the user can (more conveniently) type:
command("user's command here")

这篇关于如何从Chrome的Javascript控制台获取输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆