Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:06:29+00:00 2026-05-28T20:06:29+00:00

i am having trouble with image loading and triggering with safari/mobile safari. i have

  • 0

i am having trouble with image loading and triggering with safari/mobile safari. i have a custom object that draws on a canvas but needs to wait until an object image property has loaded because it uses the dimensions of the image when drawing. the below code works fine on ff but fails in safari:

function canvasSlider(){
    this.slideImg=new Image();
    this.slideImg.src="images/back_button.png";
    this.somevalue=55;
}
canvasSlider.prototype.init = function (){
    alert(this.slideImg.complete + ', ' + this.slideImg.height+', ' + this.somevalue);
}
var myObj = new canvasSlider();
myObj.init();

in safari this will always return false for this.slideImg.complete

How can i use this.slideImg.onload=somefunction(); and always ensure the canvasSlider object is passed?

function canvasSlider(){
this.slideImg=new Image();
this.slideImg.onload=somefunction(this);
this.slideImg.src="images/back_button.png";
this.somevalue=55;
}
function somefunction(obj){
alert(obj.slideImg.complete+', '+obj.slideImg.src);
}
var myObj = new canvasSlider()

this doesn’t work. any ideas?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:06:30+00:00Added an answer on May 28, 2026 at 8:06 pm

    Images load asynchronously so you have to trigger the drawing operation when the image is successfully loaded. You were on the right path with onload. You can do that like this:

    function canvasSlider(readyFunc){
        var self = this;
        this.slideImg=new Image();
        this.slideImg.onload = function() {
            self.init();
            if (readyFunc) {
                readyFunc.call(self);
            }
        };
        this.somevalue=55;
        // The last thing you should do in the constructor is set the .src value
        // That's because if the image is in the cache, some browsers will trigger
        // onload immediately when you set .src and we want the canvasSlider object 
        // to be fully formed when init() and readyFunc() are called.
        this.slideImg.src="images/back_button.png";
    }
    canvasSlider.prototype.init = function (){
        alert(this.slideImg.complete + ', ' + this.slideImg.height+', ' + this.somevalue);
    }
    var myObj = new canvasSlider(function() {
        // The slider is ready with the image loaded here 
        // and .init() has already been called.
        // "this" right here is the canvasSlider object
        // you can do anything else you wanted to do once the image was loaded
    });
    // The image is not necessarily loaded here.  
    // You have to put anything that relies on the image being loaded in the 
    // above callback to assure it is not executed until the image is loaded.
    

    Note: when testing your code, some browsers will fire onload immediately if the image is in the browser cache. You should test both ways (with the image in the browser cache and without the image in the browser cache) to make sure that both cases are working properly. It is common for developers to think everything works fine (because the image is in their browser cache) and then it doesn’t work for the very next user who tries it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble loading an image from My.Resources. I have already tried a no.
I'm having trouble explaining this but here it goes: I have a custom accordion
I'm having trouble loading image data into a draggable window using EXT JS. The
I am having trouble implementing image rotation in CUDA. I have a very simple
I'm having trouble roating an image around itself using Canvas. Since you can't rotate
I'm having trouble with displaying image from db. I think that method for saving
We've having trouble deploying a web service that works in our development environment, but
Good day all, I am having some trouble with image permissions. I am loading
Having trouble with MKAnnotation. Have a custom pinview and works fine for the first
I'm trying to make an SDL application in Xcode, but I'm having trouble loading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.