[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-02-13
2
Medium Priority
?
891 Views
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='http://mysite.com/widget.aspx'></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?
0
Comment
Question by:rbanks303
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1500 total points
ID: 23640176
Perhaps
<div id="contentContainer"></div>
<script type='text/javascript' source='http://mysite.com/widget.aspx'></script>
<script type="text/javascript">
var img = new Image()
img.src='http://www.mysite.com/logo.gif?'+Math.random();
img.onload=function() {
 document.getElementById('contentContainer').innerHTML=stuffFromYourOtherScript()
}
</script>

and not use document.write
0
 

Author Comment

by:rbanks303
ID: 23821565
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

873 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