Executing a command by javascript when clicking on a link
See original GitHub issueIs there a way to make the following work without having to manually press enter? I need this to make a small automation tool.
<div id="terminal-container"></div>
<div id="commands">
<a href="javascript:exec('ls -la');">ls -la</a>
<a href="javascript:exec('sudo su');">sudo su</a>
</div>
<script>
function exec(cmd) {
term.send(cmd); // needs manual Enter
term.write(cmd); // also needs manual Enter
term.writeln(cmd); // although the cursor advances to the next line, the command does not get executed
}
</script>
I have searched the issues and the closest thing I found was this comment offering this method:
process.send({
event: 'input',
data: text
});
But where is process
exposed? It does not seem to be accessible thorough term
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
call javascript function on hyperlink click - Stack Overflow
The onclick event handler captures a click event from the users' mouse button on the element to which the onclick attribute is applied....
Read more >HREF JavaScript: Call JavaScript Functions - Udemy Blog
HREF JavaScript is a method to easily call a JavaScript function when a user clicks on a link on a website. If you've...
Read more >Execute JavaScript on link click | Example code
There are many ways to Execute a JavaScript function in an HTML document. Using the onclick event attribute simple way to Execute JavaScript...
Read more >Running onclick JavaScript command using 'Inject JS Script'
The link I'm trying to click on has a piece of code written in javascript; the onlick looks like onlick=“javascript:code” whilst the href...
Read more >Links used to activate JavaScript functions - Flavio Copes
When you are creating an app using plain JavaScript, sometimes you'll have the necessity of triggering a function when the user clicks a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Tyriar Used pty.write(“\r”) and was able to execute the commands
You need to write it to node-pty, not xterm.js. You’re trying to simulate an xterm.js onData event which would be forwarded to node-pty, so call whatever you’re using in your
onData
event handler.Key presses: xterm.js -> node-pty Process data: node-pty -> xterm.js