I am a really recent starter with JavaScript. I have a simple Python Code, that opens a Bookmark for me and I want to create a Button in a .html that can run the code and open the bookmark.
This is my code so far:
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/3/w3.css">
<body>
<!-- Content will go here -->
<form>
<script type="text/javascript">
function randomSet() {
const { spawn } = require("child_process");
const childPython = spawn("python3", ["C:\\Users\\Rafi\\OneDrive\\Python\\random_set.py"]);
childPython.stdout.on("data", (data) => {
console.log(`stdout: ${data}`) ;
});
childPython.stderr.on("data", (data) => {
console.error(`stderr: ${data}`) ;
});
childPython.on("close", (code) => {
console.error(`child process exited with code ${code}`) ;
});
};
</script>
<label for="tip">Random Set!</label><br>
<input id="choose_set" type="button" value="Listen Now!" onclick='randomSet()'><br>
</form>
</body>
</html>
If I run the function randomSet in a seperate .js file it works fine. Just the integration to HTML does not work. Why is that?