Grow your CSS skills. Land your dream job.

AJAX initial page not loading in IE7

  • # January 16, 2013 at 8:48 am

    I’m having an issue with AJAX and I can’t seem to find a straight answer anywhere…

    I’m currently working on several sites based on the same AJAX technique, using the ba-hashchange.js plugin.

    I’m using the index page as an empty shell that once loaded then loads in the home page via AJAX, ie. http://www.mydomain.com becomes http://www.mydomain.com/#home/

    Here’s a code snippet:

    $(document).ready(function () {

    if (window.location.hash == “”) {
    window.location.hash = “home/”;
    };

    });

    This technique works perfectly on all browsers I’ve tested on, with the exception of IE7. In IE7 the index page loads and the URL changes to /#home/, but the content doesn’t load in. If I refresh the page, or click on a new page the content loads perfectly. It’s just the initial load that’s the problem.

    Does anyone have any experience with this or a similar issue?

    # January 16, 2013 at 5:30 pm

    Maybe you need to trigger a hash change event after you change it?

    $(document).ready(function () {

    if (window.location.hash == “”) {
    window.location.hash = “home/”;
    jQuery(window).trigger( ‘hashchange’ );
    }

    });

    # January 16, 2013 at 5:46 pm

    Just a slight change, both will work fine

    $(document).on(‘hashchange’,function(){
    if(window.location.hash == “”) {
    window.location.hash = “home/”;
    }
    }).trigger(‘hashchange’);

    # January 17, 2013 at 2:39 am

    Thanks guys, @Mottie your solution works perfectly, @karlpcrowley your solution looks neat but unfortunately it doesn’t work.

    Got this from @ChrisCoyier, might be of interest to you or anyone else who finds this thread:

    [http://css-tricks.com/rethinking-dynamic-page-replacing-content/](http://css-tricks.com/rethinking-dynamic-page-replacing-content/ “”)

    # January 17, 2013 at 4:36 am

    Ha silly me, it should start with $(window) not $(document)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".