Search code examples
jquerycssmacosgoogle-chromewebkit

Jquery reload vs Press enter on Address bar


I'm using some jquery functions to align the elements on my page and not just css. On firefox it works perfectly. On chrome (under mac os x) i have some weird problem.

If i just type on the URL Bar the address and press Enter it runs ok. If i do a command + r (same thing as using ctrl + r) it dont runs the jquery align.

enter image description here

enter image description here

As you can see in the second image, the position is messed. if i go and just hit Enter with the address bar selected, or resize... so it runs the jquery again, it fix the positions.

Is there a way to force to run the $(document).ready().

I don't know why it is happening, i tried to put the script on the end of the html with and without the $(document).ready(), in the beginning of the file i already uses $(document).ready().

It seems to be an problem with the web-kit as the safari have the same problem.

I noticed one thing:

If i put an alert on the page. If i do a command + r the alert appears before the images loads. If i press the Enter on the Address bar the alert appears after. So it seems the jquery $(document).ready() runs after the images are loaded.


Solution

  • Fixes it with

    $(window).load
    

    It seems the $(window).load waits for the images to be loaded.