Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when loading the javascript #5

Open
Schlumpf9 opened this issue Jan 19, 2017 · 2 comments
Open

TypeError when loading the javascript #5

Schlumpf9 opened this issue Jan 19, 2017 · 2 comments
Labels
support Indicates a request for help / clarification

Comments

@Schlumpf9
Copy link

When I run your script in head I get the following error:
TypeError: document.body is null

To fix this you have to put the js code below the body tag. Is there any other fix to have the js in the head section? This appears in firefox and chrome.

@ghost
Copy link

ghost commented Feb 7, 2017

This kind of issue often happen when you're trying to interact with the DOM when it is not properly loaded (i.e. too soon).

You can add an event listener in order to wait until the DOM is fully loaded before interact with it.

You can use $.ready(function(){/* your code here */}) with jquery or document.addEventListener('DOMContentLoaded', function(){/* your code here */}) in native javascript.

Thus, your javascript code will wait the end of the page load to add your notification system.

@dominique-mueller
Copy link
Owner

The easiest way is to load the library with a "defer" attribute attached. For example:

<script src="notification.min.js" defer></script>

For details, see https://www.w3schools.com/tags/att_script_defer.asp

@dominique-mueller dominique-mueller added the support Indicates a request for help / clarification label Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Indicates a request for help / clarification
Projects
None yet
Development

No branches or pull requests

2 participants