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

232
Views
How to access webpack created js functions in html

I have an express server that compiles handlebar files into html based on the route and I am using webpack to compile javascript files into one js file per page the user navigates to.

I am trying to access global functions that I defined in my javascript files from my html files to register onclick events and I can't seem to get it to work. The page loads fine

Here is the resulting HTML from the handlebars file:

<button onclick="OnButton_Open()">

Here is the function in the webpack compiled javascript:

OnButton_Open = function  () {
    here's my function
}

If I leave the function like above, the page loads, but when I click I get an error that it can't find OnButon_Open.

window.OnButton_Open = function  () {
    here's my function with the global prefix
}

If I prefix the function with window. which is what I thought that I had to do in this situation, I will actually get a reference error as the page loads that OnButon_Open is not defined. This is what the resulting webpack code looks like at the spot where I get the error:

/* harmony export (immutable) */ __webpack_exports__["OnButton_Open"] = OnButton_Open;

Is there a better way to make those functions accessible to the outside world? I'd happily put everything in the global scope for now until I can modularize this app a bit more.

about 4 years ago · Santiago Trujillo
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!