move.js icon indicating copy to clipboard operation
move.js copied to clipboard

document.body.style called before body exists

Open FossPrime opened this issue 10 years ago • 9 comments

Uncaught TypeError: Cannot read property 'style' of null

... Move is initialized before body exists. There are workarounds... non of which should be necessary.

Line 284 var styl = document.body.style;

FossPrime avatar Mar 06 '14 21:03 FossPrime

thanks for reporting,

yeah in general you should use defer until the body exists, you can either include the script after the body is loaded or body.onload or something.

examples should be fixed by me but i'm super lazy :P

yields avatar Mar 06 '14 21:03 yields

I still get this error, how come the issue is closed?

hems avatar Jul 01 '14 16:07 hems

Hi there,

I still get this error : "Uncaught TypeError: Cannot read property 'style' of null " at the exact same line specified above. Is there any fix ?

Thanks, Loris1634

DevJS avatar Aug 11 '14 10:08 DevJS

@hems @Loris1634

can you guys come up with a tiny html file that reproduces it ?

yields avatar Aug 11 '14 10:08 yields

Yep. Here it is : http://pastebin.com/2UYcwjsB

I was not really accurate earlier. Here is the exact error I get : TypeError: document.body is null move.js:284 (I am using Firefox)

DevJS avatar Aug 11 '14 10:08 DevJS

To solve this error, just put move.js before </body> :) Works like a charm!

felquis avatar Sep 01 '14 17:09 felquis

@felquis some people don't include the js on the html source..

hems avatar Sep 01 '14 18:09 hems

Hey, we just encountered this bug in the nastiest of ways: Our module is loaded in the head but MoveJS is only invoked later on runtime.

This resulted in a race condition where we would function normally most of the time, but if we loaded faster than the dom we would get this error.

We would like to issue a pull request to at least workaround this issue. Perhaps an optional flag to skip to document.body.style check.

What do you think?

dortzur avatar Jan 16 '17 09:01 dortzur

I have same issue. :(

jinkwon avatar Mar 07 '17 05:03 jinkwon