How to read Console strings?

1

I am trying to make a code that reads a string from the Console of the browser and assigns the value of the string in the id "txtTextoResposta" .

To make it more illustrated, I want to do similar to C # , when we do this:

string x = Console.ReadLine();

I tried with ReadLine() , but it did not work:

var x = readline();
document.getElementById("txtTextoResposta").innerHTML = x;

I've also tried Console.Log , but it returns an error:

var x = console.log;
document.getElementById("txtTextoResposta").innerHTML = x;

Error:

  

function log () {[native code]}

    
asked by anonymous 08.07.2017 / 22:55

2 answers

2

The browser does not allow JavaScript code to read the contents of the console. Probably because of security. Short answer, but I can not see the way around, at least in the browser.

    
08.07.2017 / 23:11
1

You can use prompt

console.log(prompt('Input'))
    
08.07.2017 / 23:27