Brian Peters
Brian Peters

Reputation: 297

How do I preload HTML that is written by a Javascript on page load?

So here is what I am trying to achieve. I currently have a FeedBurner script in my webpage. I use the <script> tags for the feed and when the page loads, the script generates the feed HTML. What I'm trying to do is to have all the HTML associated with the feed to preload and then fade in. I tried putting the script in an external file and making an Ajax call but that didn't actually wait till everything was finished loading.

I am currently using jQuery.

Thanks.

Upvotes: 0

Views: 139

Answers (3)

skeelsave
skeelsave

Reputation: 178

Use the ajax call on window.load like Sushanth said along with appending it with display:none and then fading it in.

$(window).load(function() {
      $content = $.get();
      $content.css('display', 'none').appendTo('#my_element').fadeIn()
});

Upvotes: 0

polin
polin

Reputation: 2845

You can use your JS function like this on your body part.

<body onload="func()">

Upvotes: 0

Sushanth --
Sushanth --

Reputation: 55750

Put that code in window load function instead of DOM Ready

$(window).load(function() {
      // Make ajax request here and check if that helps
});

Upvotes: 1

Related Questions