Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a page within which i am loading an image.
all are working fine.
I want to do an enhancement as follows;

There is a bigger size image is going to load. So it will take some time to load(Let it 15 seconds).
But a small size image takes 4-5 seconds to load.

So i want to give a confirm box to the user after 10 seconds whether the user want to continue or discard it in case of bigger images.
Posted
Comments
You can show Progress Bar, but I don't know whether you determine the time and show message according to that.
Member 10284541 12-Nov-13 1:28am    
i have already implmented progress bar.
But I have to show a confirm box if the progress bar is running for more than 10 seconds.\

You can get XHR response header data and check the image size and then show confirm box:

http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method

This function will get the filesize of the requested URL:
JavaScript
function get_filesize(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open("HEAD", url, true); // Notice "HEAD" instead of "GET",
                                 //  to get only the header
    xhr.onreadystatechange = function() {
        if (this.readyState == this.DONE) {
            callback(parseInt(xhr.getResponseHeader("Content-Length")));
        }
    };
    xhr.send();
}

get_filesize("http://example.com/foo.jpg", function(size) {
var dowload = true;
if(size>maxSize)
 dowload = confirm("The size of image is: " + size + " bytes and may take 10 to 15 sec, do you want to proceed?");
if(dowload)
 getImage();//Your function to show image.
});
 
Share this answer
 
create a separate thread at the be beginning of file upload and close that thread after file upload complete.
But inside thread u have to start a timer and check if time greater than 10sec or not.
if got true then set a message box .
 
Share this answer
 
I got the solution as below;

Call it on ready function.

var checkImageLoad = false ;

var counter;

counter = setInterval(checkLoading, 1000); //1000 will run it every 1 seconds

C#
var count = 0;
function checkLoading() {
           count = count + 1;
      if (count >= 10 && checkImageLoad == false)
       {
                Confirm();
                clearInterval(counter);
        return;
       }
}


//Creates Confirm Box when there is a delay in image loading
function Confirm() {
$("#divConfirm").dialog({

modal: true,
width: 500,
resizable: false,
buttons: [{

text: 'Yes',
click: function () {
$(this).dialog('close');
}
},
{
text: 'No',
click: function () {
//Write your code what you want to do if NO
}
}]
});

$(".ui-dialog-titlebar").text("Confirm");
$(".ui-dialog-titlebar").css("text-align", "center");
$(".ui-widget-content").css("padding-left", 5);
$(".ui-widget-content").css("padding-right", 5);
}
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900