rstacruz / nprogress

For slim progress bars like on YouTube, Medium, etc
http://ricostacruz.com/nprogress
MIT License
26.06k stars 1.81k forks source link

"Uncaught TypeError" on getting body style! #41

Open fkomaralp opened 11 years ago

fkomaralp commented 11 years ago

Hi, there is a bug "Uncaught TypeError: Cannot read property 'style' of null " on this line ; @216 // Sniff on document.body.style var bodyStyle = document.body.style;

Mithgol commented 11 years ago

How do you call that script: Node's require() or HTML <script src="…">?

fkomaralp commented 11 years ago

Using the normal way, <script type="text/javascript" src="<?=assets_url()?>js/nprogress/nprogress.js"></script>

Mithgol commented 11 years ago

Interesting.

What's the browser?

Does the assets_url() point to some other domain?

fkomaralp commented 11 years ago

Chrome 29. (Tested on other browsers: IE10, Opera15, FF24 I got same error) No, assets_url() working good.

But i'm fixed this problem like that. var bodyStyle = document.body.style; changed to var bodyStyle = document.head.style;. My thing is that, in generally all style properties on the head tag!.

Maybe problem's me. Please look at this web site i'm used this script on the blog area.

Used in this area http://gayretsoft.com/home/blog Script path http://gayretsoft.com/assets/js/nprogress/nprogress.js Function of getPositioningCSS For me, this error is normal.

Now, script is working perfect.

Mithgol commented 11 years ago

@rstacruz Maybe nprogress should rather use document.getElementsByTagName('style') or some other instrument that does not depend on the <style> tag's location.

riccardoscalco commented 10 years ago

Could this help? https://github.com/zhouzhuojie/meteor-nprogress/issues/1

oxbambooxo commented 8 years ago

I catch this error too, I find the cause is when NProgress.start(), the tag may not loading in page,then document.body will be null, I put the 'NProgress.start()' in bottom of the page, it is ok.

/ meybe $(document).ready(function () {NProgress.done()} is usefully. /

nononoy commented 7 years ago

+1 Uncaught TypeError: Cannot read property 'style' of null(…). ROR 4

cjmaxik commented 7 years ago

Problem still not solved

adrianobarroso commented 7 years ago

I'm having the same problem.

renatoleite commented 7 years ago

You need to call NProgress.start() in the bottom of the page, if you call in the begin will throw an exception because the body tag not was created yet.

ricardo commented 6 years ago

You are probably placing the script inside the head tag. Try inserting the start() inside the body tag instead.

gujiman commented 6 years ago

if you place it at the top then you can do something like:

        var ngProgRun = setInterval(function () {
              if (document.body != null) {
                    clearInterval(ngProgRun);
                    NProgress.start();
              }
        }, 10);