views:

232

answers:

3

I know this exists out there, somewhere but I haven't found it in a few hours of searching. I simply have to load a clients external page into an IFRAME, but I want to use jquery ui to present the loading image while it's grabbing the external data.

Simple yes, but I've seen pieces of this not the whole thing.

+2  A: 

Something like this?

Live Example: http://jsfiddle.net/CPadm/

EDIT: Updated so that the iframe is hidden until loaded.

Live (updated) Example: http://jsfiddle.net/CPadm/3/

HTML

<div id="button">Click to load</div>

<iframe></iframe>

<div id='loading'>Page is loading...</div>​

CSS

iframe {
    display: none;
}
#button {
    background: blue;
    color: white;
    padding: 10px;
    width: 100px;
}
#loading {
    width: 300px;
    padding: 20px;
    background: orange;
    color: white;
    text-align: center;
    margin: 0 auto;
    display: none;
}​

jQuery

$('iframe').load(function() {
    $('#loading').hide();
    $('iframe').show();
});

$('#button').click(function() {
    $('#loading').show();
    $('iframe').attr( "src", "http://www.apple.com/");
});​

Relevant jQuery docs:

patrick dw
A: 

Thanks it's close I'm actualy trying to fire the onLoad of the page, since the iframe loads at page load and not on a click event.

imaginedesign
Thanks I got it working... and that jfiddler is pretty sweet.
imaginedesign
@imaginedesign - Glad you got it working! FYI, you should use comments to send messages instead of posting a comment in a new answer. Keeps things neat, and stackoverflow will notify the user if you post a comment under their answer.
patrick dw
@imaginedesign - Also, please remember to click the checkmark next to an answer to designate it as the "Accepted" answer. :o)
patrick dw