question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

script onLoad is not triggered

See original GitHub issue

The onLoad event handler isn’t triggered for a script element

<script src="https://..." async defer onLoad={() => console.log(1)} />

(I tried with onload as well)

live demo: https://jsfiddle.net/crl/uks4pc60/

react version: 16.5.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:11

github_iconTop GitHub Comments

12reactions
BiosBoycommented, Jun 5, 2020

The same problem here. Did someone found a solution?

7reactions
liamhessioncommented, Sep 28, 2020

@BiosBoy - in my case, which could be different from ^ his and yours, it was solved by writing the script i wanted executed onLoad as a string of Javascript:

<script type="text/javascript" src={'/widget.js'}
  onLoad={`console.log('HAAEHHHAHHEHHHA')`}
></script>

Here i was including a script in the head of the page by including this element within a react-helmet <Helmet> tag.

These did NOT work as desired, that is, only running the onLoad code once, after the javascript file has been loaded:

<script type="text/javascript" src={'/widget.js'}
  onLoad={console.log('HAAEHHHAHHEHHHA')}  { /* runs many times, as the page is re-rendered */ }
></script>
<script type="text/javascript" src={'/widget.js'}
  onLoad={() => console.log('HAAEHHHAHHEHHHA')}  { /* original asker's solution, never ran for me */ }
></script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript onload not working [closed] - Stack Overflow
Javascript onload not working [closed] · 1. any error in the browser console. – Arun P Johny · 3. There is nothing wrong...
Read more >
Onload not firing on Chrome for Windows | WordPress.org
I'm having a an issue, where the onload JavaScript is not firing on Chrome for Windows, while it works on Firefox and Chromium....
Read more >
Resource loading: onload and onerror
script.onload. The main helper is the load event. It triggers after the script was loaded and executed. For instance: let script = document....
Read more >
Window: load event - Web APIs - MDN Web Docs - Mozilla
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images.
Read more >
HTML onload Event Attribute - W3Schools
The onload attribute fires when an object has been loaded. onload is most often used within the <body> element to execute a script...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found