Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  69] [ 6]  / answers: 1 / hits: 17121  / 12 Years ago, tue, august 21, 2012, 12:00:00

Using JavaScript, is there a way to detect whether or not an external script (from a third-party vendor) has completely loaded?



The script in question is used to pull in and embed the markup for a list of jobs and, unfortunately, doesn't make use of any variables or functions. It uses document.write to output all of the content that gets embedded in my page.



Ideally, I'd like to display some kind of loading message while I'm waiting for the external script to load, and if it fails to load, display a We're sorry, check back later... message.



I'm using jQuery on the site, but this external script is called before I make the jQuery call.



Here's what the document.write stuff from the external script looks like:



document.write('<div class=jt_job_list>');
document.write(
<div class=jt_job jt_row2>
<div class=jt_job_position>
<a href=http://example.com/job.html>Position Title</a>
</div>
<div class=jt_job_location>City, State</div>
<div class=jt_job_company>Job Company Name</div>
</div>
);

More From » jquery

 Answers
293

Thanks for the assistance above, especially ngmiceli for the Steve Souders link!



I decided to take what's probably a lazy approach, and also forego the loading message:



$(document).ready(function(){
if ($('.jt_job_list').length === 0){
$('#job-board').html(<p>We're sorry, but the Job Board isn't currently available. Please try again in a few minutes.</p>);
};
});


Pretty simple, but I'm looking to see if an element with the .jt_job_list class is in the dom. If it isn't, I display an error message.


[#83501] Monday, August 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
miles

Total Points: 256
Total Questions: 111
Total Answers: 104

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;