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

  • Home
  • SEARCH
  • 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 8840947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:35:18+00:00 2026-06-14T10:35:18+00:00

I have a function which receives either a preloaded JS image object or an

  • 0

I have a function which receives either a preloaded JS image object or an image url. This is passed in as the photo variable.

I perform a check to see whether the ‘photo’ var is a string or not. If it is I create a new image object and use the onload event to fire the generateSlide() function passing in the newly created image object as seen below:

renderSlide: function (slideindex, photo, external, count, text) {
        var self = this;
        var image = new Image();
        if (typeof (photo) == 'string') {
            image.onload = function () {
                self.generateSlide(slideindex, image, external, count, text);
            };
            image.src = photo;
        } else {
            image.src = photo.src;
            self.generateSlide(slideindex, image, external, count, text);
        }
 },

If the ‘photo’ var is a preloaded JS image object I simply run the function itself passing the image object into generateSlide();

Everything works great however for some reason in IE 9 I cannot simply pass through the ‘photo’ var directly into the generateSlide() function. I have to create a new image object and set the src to match the photo object’s src attribute.

This makes no sense to me and I can’t understand why this would be?

In the cases where the photo var is an actual JS image object it is confirmed as loaded elsewhere. ( I am preloading assets );

In summary, the code above works fine but can anyone explain WHY I have to create a new image object and cannot simple pass in the original one? Is there a more elegant solution? So far I haven’t noticed any problems with the above method but is anyone aware of any pitfalls using this approach.

Thanks in advance

  • 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-06-14T10:35:20+00:00Added an answer on June 14, 2026 at 10:35 am

    It sounds like an issue with scope. Have you tried putting the call in a closure to make sure the correct photo is captured?

    renderSlide: function (slideindex, photo, external, count, text) {
            var self = this;
    
            if (typeof (photo) == 'string') {
               var image = new Image();
                image.onload = function () {
                    self.generateSlide(slideindex, image, external, count, text);
                };
                image.src = photo;
            } else {
              (function(photo){
                self.generateSlide(slideindex, photo, external, count, text);
              })(photo);
            }
    

    },

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

Sidebar

Related Questions

I have a function which sends a command over serial, then receives a response
Can I´m asking for advice. I have function which should return javascript object function
I have a function which looks something like this, it returns a noncopyable class
I have this static function which basicly makes a connection to a webpage, send
I have a function which receives a list item. When it does, I want
as a simple example, i have a C function which receives an int,increment it
I have a function which takes as an argument an XDocument object. I need
I have a Python function which receives numerous variables, and builds an SQL query
My question is about Javascript. I have a Callback function which receives a Position
I have a Functor which I need to send to a function which receives

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.