1

I would like to implement the Javascript command shell in the browser for the user to be able to press a ‘run code’ button to execute the code right in the browser (like code sandbox in Eloquent Javascript):

enter image description here

Are there any libraries that I can use to implement it?

Many thanks!

1

2 Answers 2

2

I don't think that you need a library to do what you want. You can simply read the code from the DOM element and then pass it to the eval() function to run it; see here for an example: http://www.danielsadventure.info/Javascript/Javascript.html

<input
    type='button'
    value='Run Code'
    onclick="eval(document.getElementById('txtCode').value);" />
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, Daniel, this iv very helpful
I'm glad it helped. Please don't forget to click the check mark next to the best question so that people know that this question is answered.
Sorry, I am new in StackOverflow and not sure where is this checkmark. Would you be so kind to share a screenshot?
You have to be logged in. Next to each answer, there is a big number with an up arrow, and down arrow, and a checkbox. You can click the checkbox next to the best answer to mark your question as answered so that people know not to try to answer it again.
0

You could use JQuery terminal. It's quite flexible. Take a look specially to this example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.