最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Showing a loading animation for an iframe in a jQuery UI modal dialog - Stack Overflow

programmeradmin4浏览0评论

UI experts, I'm trying to get a slow website loaded in an iframe within a jquery modal dialog, but I'm having trouble. This is my use case:

  1. open a jquery dialog, with a single "loading..." gif
  2. load a different URL in the background
  3. once loaded, replace the gif with the URL

I'm able to open the URL directly with code as below:

    var popup = $('<div id="popup123" class="dialog"></div>').prependTo('body');
    popup.prepend('<iframe style="display:none" class="dialogIFrame"></iframe>');
    $('.dialogIFrame').attr("src", 'http://myslowsite');
    $('.dialogIFrame').show();
    popup.dialog({
        modal: true,
        title: 'Site',
        width: 1000,
        height: 500,
    });

So my question is - how do I add a "loading..." gif to the mix? Should be possible - but I can't seem to figure out!

Thanks in advance!

UI experts, I'm trying to get a slow website loaded in an iframe within a jquery modal dialog, but I'm having trouble. This is my use case:

  1. open a jquery dialog, with a single "loading..." gif
  2. load a different URL in the background
  3. once loaded, replace the gif with the URL

I'm able to open the URL directly with code as below:

    var popup = $('<div id="popup123" class="dialog"></div>').prependTo('body');
    popup.prepend('<iframe style="display:none" class="dialogIFrame"></iframe>');
    $('.dialogIFrame').attr("src", 'http://myslowsite');
    $('.dialogIFrame').show();
    popup.dialog({
        modal: true,
        title: 'Site',
        width: 1000,
        height: 500,
    });

So my question is - how do I add a "loading..." gif to the mix? Should be possible - but I can't seem to figure out!

Thanks in advance!

Share Improve this question asked Dec 7, 2012 at 6:37 ragebiswasragebiswas 3,8789 gold badges40 silver badges42 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Here is an example of creating an iframe, directing it to a site and performing a callback when it finishes loading: http://jsfiddle/74nhr/109/

$(document).ready(function() {
    var status = $('#status');
    var iframe = $('iframe');

    status.val('Loading...'); // show wait

    iframe.on('load', function() {
        status.val('Done!');  // remove wait, done!
    });

    setTimeout(function() {
        iframe.attr('src', 'http://www.archive');
    },
    1000);
});
​

See this. Hope it helps.. http://jsfiddle/CEJhb/1/

var popup = $('<div id="popup123" class="dialog"><img id="load" src="http://jsfiddle/img/logo.png" alt="loading..."/></div>').prependTo('body');

popup.prepend('<iframe style="display:none" class="dialogIFrame"></iframe>');
var $iFrame = $('iframe');

$iFrame.load(function() {
$('.dialogIFrame').show();
$('#load').hide();
});

$('.dialogIFrame').attr("src", 'http://www.google.');

popup.dialog({
modal: true,
title: 'Site',
width: 1000,
height: 500
});​
发布评论

评论列表(0)

  1. 暂无评论