I'm trying to create a dynamic template for students registration form and I'm trying to print it,
the problem is while pressing the print button for the first time, it prints and everything works fine but after the second time it's not working until restarting the server itself although it shows the print window.
Here is main.js
$('#elemID').submit(function(e) {
e.preventDefault();
var x = $('#numberOfStudents').val();
var output = [];
for (var i = 1; i <= x; i++) {
output.push(`<div><p> student number #0${i} </p></div>`);
}
var data = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
</head>
<body>
<h4>Registation Form</h4>
<h5>Full Name:</h5>
<h5>gender:</h5>
.
.
.
</body>
</html>
`
$.print(data);
})
print.ejs
<form id="elemID">
<input type="number" id="numberOfStudents" placeholder="Number of students eg. 1....2....3">
<button type="submit" id="printApplication">Print Application</button>
</form>
index.js (server side)
const {app, BrowserWindow, Menu } = require('electron')
// express
const express = require('express'),
expApp = express(),
server = require('http').createServer(expApp),
db = require('./db/mongoose'),
parentRoutes = require('./routes/parents'),
studentRoutes = require('./routes/students'),
port = process.env.PORT || 3000
let mainWindow
// load the url on listening
function onListening() {
mainWindow.loadURL('http://localhost:3000')
}
// Function create a window
function createWindow() {
// create a new window for main window
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true
}
})
// express usage
expApp.set('port', port)
expApp.use(parentRoutes)
expApp.use(studentRoutes)
expApp.use(express.static('../semantic'))
// listening to port
server.listen(port, () => {console.log(`listening to port ${port}`);})
server.on('listening', onListening)
}
app.on('ready', createWindow);
I'm using jquery.print.js
Everything works fine on the first submit ut on the second time the print function doesn't work whatever printing or saving the file except if I restart the server.
I don't know what's wrong ?...please tell me if something not clear.
so please could you help me on this?