7

That's realy strange issue, i have quite a lot of plugins and custom scripts in my page and normaly it all works just fine, but if i would try to refresh page, not just click on some link, some of my scripts just stops working, mostly the ones who is changing css properties, my firebug doesn't show any errors, what could be causing something like that?

Trott
  • 66,479
  • 23
  • 173
  • 212
Linas
  • 4,380
  • 17
  • 69
  • 117
  • Have you tried clearing your browser cache? Do you get the same problem in all browsers? – Christofer Eliasson Feb 05 '12 at 14:47
  • I've tried to clean it now and it didn't help, and mostly i get this in chrome, but time to time it happens in mozila or opera to – Linas Feb 05 '12 at 14:52
  • Maybe i have to much of jquery in my page and it simply can't load everything in time? even thou i use `ready` function. – Linas Feb 05 '12 at 14:55
  • make sure you are loading everything when the script first loads, if your pages require loading of objects by the users events, then make sure you're initializing the code onLoad or `ready` without any user events.. Hard to say without seeing the code. – Control Freak Feb 05 '12 at 15:15
  • after some debuging i found my problem (more or less), so it seems that `$(document).ready` doesn't do his job very well, it runs before half of my page elements is loaded that's why i get all of this mess – Linas Feb 05 '12 at 15:36
  • I had the same issue, when performed a redirection from one page to another on facebook app. $(window).load() works fine! – Arsen K. Jul 31 '12 at 16:54
  • `$(window).load()` can be slow on sites with lots of external resources; if I were you I'd rather tried to make it work with `$(document).ready()`. – mgol Jul 31 '12 at 20:51
  • just to clarify some things : the method `$(document).ready()` is waiting for the DOM to be ready : so basically, even if some scripts, or ressources is not loaded yet, it don't really care. and the method `$(window).load()` is waiting for every element of the page to be loaded. it means pictures, scripts, etc ... – Alex Jun 03 '15 at 09:22

2 Answers2

5

Answer from original poster:

So the problem was that i used $(document).ready() what i realy needed was $(window).load()

Trott
  • 66,479
  • 23
  • 173
  • 212
3

I know this is an old question I stumbled upon. Anyway, my answer might help another when the same problem arises. Unfortunately I haven't got the reputation to comment on Trott's answer above.

That being said, if you are using jQuery 1.8 or any version after his, then use $(window).on('load', function() { ... });. The $(window).load() was deprecated in jQuery version 1.8 and will throw the error jquery url.indexOf is not a function (at least in jQuery 3.4.1)

M. Groenhout
  • 386
  • 2
  • 10