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

  • SEARCH
  • Home
  • 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 3673538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:44:45+00:00 2026-05-19T02:44:45+00:00

I serve ads through an iFrame. The ad network’s servers are much slower than

  • 0

I serve ads through an iFrame. The ad network’s servers are much slower than mine, so I asyncronously load the iFrame on the window.onload event.

// (using Prototype library)
Event.observe(window, 'load', function() {
  $('ad').writeAttribute('src', '/ad.html');
  // other initialization here
});

A problem occurs when you enter the site via the browser’s back button. Unexpectedly, the ad iFrame attempts to load immediately (before the load listener above sets the ‘src’ attribute), delaying the load event for a few seconds. During these few seconds, the site is unusable because I do a bunch of initialization in window.onload.

As far as I know, this only happens in Firefox. How do I prevent this blocking load?

  • 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-05-19T02:44:45+00:00Added an answer on May 19, 2026 at 2:44 am

    Theory

    The issue you’ve noticed could be described like this: an iframe in a document loads the URL loaded in it at the moment the outer page was navigated from, not the URL specified in the outer page’s HTML source (or an empty page in your case).

    The fact that it delays onload is just a corollary: the load event is delayed until all the resources (images, frames, etc) are finished loading.

    I couldn’t find documentation explaining that it should happen this way, nor any bug reports acknowledging it as a known issue, but FWIW I see exactly the same behavior with Google Chrome 10.0.612.3 on the testcase below.

    This behavior, even though unintuitive in your case, has some logic behind it: document loads in frames historically are recorded in the session history (back/forward navigation history). Suppose you open a site, that has its main content in a frame, and navigate the inner iframe. After going away from the site, then returning via the back button, the browser should arguably load the last loaded page in the frame.

    Solutions

    Surprisingly, this doesn’t appear to be a common question, so these suggestions are based on my understanding of the issue, I haven’t tested them in any scenario more real than the testcase below.

    1. The best experience for the user would be if you made the bfcache work. As far as I can see, this would require the ad document be cacheable (using different URLs to show different ads, instead) and possibly changes to the JS framework you use (if it happens to always break bfcache, I don’t know, this used to be a problem with other frameworks).
      If you pulled this off though, there would be no load event at all, the page would just be restored exactly in the state it was left in, and it would much snappier than anything that hits the network.
    2. The only way to prevent the iframe from loading the URL from session history I can think of is to avoid having the iframe in the HTML source. If you insert it dynamically, it wouldn’t be the “same” iframe the next time the page loads, so it would default to the URL you specify in its src.
    3. Instead of trying to prevent the iframe from loading the ad on ‘back’, you could make your code currently running off the load event not be blocked by the iframe. For this you could use the DOMContentLoaded event.

    Appendix: Testcase

    <iframe id="a"></iframe>
    <pre id="b"></pre>
    <script>
    var b = document.getElementById("b")
    b.innerHTML += "before 'load': iframe src=" + document.getElementById("a").src + "\n";
    window.addEventListener("load", function() {
      var newURL = "https://developer.mozilla.org/en/HTML/Element/iframe";
      b.innerHTML += "onload: iframe src=" + document.getElementById("a").src + "\n";
      b.innerHTML += "setting src to " + newURL + "\n";
      document.getElementById("a").src = newURL;
      b.innerHTML += "now iframe src=" + document.getElementById("a").src + "\n";
    }, false);
    
    // disable bfcache
    window.onunload = function() {}
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my web project I have to serve ads through our openx server but
I need to be able to display ads on email forwarded through a server
Does a Sleep(sometime) serve a purpose in the typical infinite window message loop, or
My app uses a WebView widget to load ads from Google AdManager. AdManager gives
I've got a Flex 3 website. I set-up adBrite in an iFrame to serve
Some of our advertisers require us to serve their ads from their server using
I am trying to better understand various platforms to serve ads in my Android
I have some questions about expandable ads and <iframe> s. I've created expandable ads
We use Google Ad Manager to serve ads. I would like to create a
I have a table which contains my ads that can be searched in sql-server-2008.

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.