Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
How to use inline JavaScript inside HTML files?

I would like to use JavaScript tags inside HTML files in Electron.

I know I can use code like this in main.js:

webPreferences: { preload: path.join(__dirname, "preload.js"), },

And then import this script in HTML files like this:

<script>alert("This works!")</script>

But why can't I just use JavaScript like this inside HTML files:

alert("Why won't this work?");

There is a default meta tag in HTML when I follow Electron's quick start guide: <meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'" />

And this I guess disables executing inline JavaScript.

So my question is, is it bad practice to use inline JavaScript like this in Electron? Should this be avoided?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

yes you can use javascript inside HTML files by using the script tag .

<script>
     //code goes here
</script>

now coming to use of inline javascript its not a good practice if you are creating a project because then it will be hard to maintain if you start working with multiple files.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!