How do I provide a javascript or iframe timeout when external server is unavailable?

Posted on 2009-02-13
Last Modified: 2013-11-19
I have a website that provides widgets that people put on their blog sidebars.  They do so by using an external script tag:

<script type='text/javascript' source=''></script>

Occasionally our server will go down which will cause all our users blogs to timeout for about 30 seconds while the browser tries to load the external script.  Obviously our users don't appreciate this.

Note we can't use the script "defer" attribute because we are writing content to the document.

I have researched the problem and found mention of people using iframes with javascript settimeout helper functions to accomplish this.   What would this look like?  Should I just AJAX (xmlhttprequest) to do this?
Question by:rbanks303
    LVL 75

    Accepted Solution

    <div id="contentContainer"></div>
    <script type='text/javascript' source=''></script>
    <script type="text/javascript">
    var img = new Image()
    img.onload=function() {

    and not use document.write

    Author Comment

    The solution above probably works - but I went ahead and used an AJAX call instead.  When the page has finished loading I do a JSONP AJAX call to our servers.  If the servers are down, the AJAX call just fails and no one gets mad.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Update field in order 21 96
    Hiding a site page from being searchable 3 41
    Website URL redirection 10 34
    scripting, exchange 35 26
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now