Reputation: 35
I have my electron window, it loads all right except that the JS is not run. I can't find out why. Here is my code:
...
<head>
<meta name="viewport" content="width=device-width">
<link href="./assets/default.css" rel="stylesheet"></link>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'unsafe-inline';">
<script>
(function() {
"use_strict";
console.log('lul'); // Doesn't log 'lul'
var jq = require("./assets/jquery.min.js");
});
</script>
</head>
...
This has been frustrating my for a while. I get no errors in the console, and no log. I am new to electron.
Upvotes: 0
Views: 1386
Reputation: 2330
That is because your function is declared but never invoked. Try:
(function() {
"use_strict";
console.log('lul'); // Doesn't log 'lul'
var jq = require("./assets/jquery.min.js");
}());
The ()
at the end makes it an IIFE (Immediately Invoked Function Expression).
As a side note, I believe the require
is going to throw an error if you run it in a browser without converting it with babel or some other transpiler.
Upvotes: 3