iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐈

How to call functions bundled with Webpack from HTML

に公開

Conclusion

  • Assign it to a property of the window object

Situation

<!DOCTYPE html>
<html>
    <body>
        <button onclick="hello()">hello world</button>
        <script src="main.js"></script>
    </body>
</html>

Example

const hello = () => {
    alert("hello");
}

window.hello = hello;

References

https://qiita.com/zaburo/items/710ab1cba98daf85ad9b
https://qiita.com/sssssshhh/questions/392d946ac676934ba9ad

Discussion