Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8326415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:45:11+00:00 2026-06-09T00:45:11+00:00

I am trying load content from another url using pushstate/html5… The content I am

  • 0

I am trying load content from another url using pushstate/html5… The content I am trying to load has a big background image which takes time to load…

So when it animates fast full image seems to come up and slide in but then image reloads again…

I tried using

image preloader/
$(document).ready()

they all break the script and can’t quite seem to figure out how to incoprate it here

    function goTo(href) {

    var left = $(window).width();
    $('#id').css("left", left);

    $.ajax({
        url: href,
        success: function (data) {

            var content = $(data).find('#id').html();

            // Windows Load Function
            $(window).load(function () {

                $("#id").html(content).animate({
                    left: '0',
                }, 'fast');

                var title = $('#id').find('h1').text();
                $('head').find('title').text(title);

            });
        }
    });
}

// check for support before we move ahead

if (typeof history.pushState !== "undefined") {
    var historyCount = 0;

    // On click of link Load content and animate
    $('.access a').live('click', function () {

        var href = $(this).attr('href');

        goTo(href);

        history.pushState(null, null, href);
        return false;
    });

    window.onpopstate = function () {
        if (historyCount) {
            goTo(document.location);
        }
        historyCount = historyCount + 1;
    };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:45:14+00:00Added an answer on June 9, 2026 at 12:45 am

    MonteCristo,

    I think this is best addressed with Deferreds.

    In the code below, a Deferred object is passed to goTo() as a second argument, animator. This Deferred is resolved inside goTo() when all images with class imgSelector have sussessully loaded. On resolution of animator the animation fires and the page’s title is changed.

    Creating animator externally and passing it to goTo() allows this Deferred to be rejected from the scope where goTo() is called. This feature is included to inhibit the animation should another click or popstate event occur before the animation fires.

    To make this work, you will need to serve each content page with a dummy off-screen foreground <img> with the same src as the problematic large background image and class="critical". This is the easiest way to trigger an event when the background image loads.

    $(function() {
        var $id = $("#id");
        var imgClass = 'critical';
        function goTo(href, animator) {
            $id.stop().css("left", $(window).width());
            $.ajax({
                url: href,
                success: function(data) {
                    var deferreds = [];
                    $id.html($(data).find('#id').html());
                    $("img." + imgClass, $id).each(function() {
                        var d = new $.Deferred();
                        deferreds.push(d);
                        $(this).on('load error', function(){
                            d.resolve();
                        });
                    });
                    $.when.apply(null, deferreds).done(function() {
                        animator.resolve();
                    });
                    $.when(animator).done(function() {
                        $id.animate({
                            left: '0',
                        }, 'fast');
                        $('head title').text($('h1', $id).text());
                    });
                }
            });
        }
    
        var historyCount = 0,
            animator = null;
    
        function getDeferred() {
            if(animator) {
                animator.reject();
            }
            animator = new $.Deferred();
            return animator;
        };
    
        if (typeof history.pushState !== "undefined") {
            $('.access a').live('click', function() {
                var href = $(this).attr('href');
                goTo(href, getDeferred());
                history.pushState(null, null, href);
                return false;
            });
            window.onpopstate = function() {
                if(historyCount) {
                    goTo(document.location, getDeferred());
                }
                historyCount++;
            };
        }
    });
    

    untested

    You may well need to debug and/or modify the code to get exactly what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load html content from another page via .load(). For example:
I am trying to load content from a remote URL in my php code.
I'm trying to load content from another page div into another page div. What
I am trying to display an image from a URL, which may be larger
I'm trying to do a loop where I load some content from another page
I'm trying to load content from one of my sites in another: <div id='include-from-outside'></div>
I'm trying to load new content to my page from database when user scrolls
I am trying to load a div from another domain and display it on
I am trying to load big image files in Java and i am getting
I'm using jQuery 1.5.2 trying to dynamically load a div from one source into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.