0

i want to call a function on load and it not working its in a iframe if that makes a difference. dont mind the html; thank you in advance.

var canvas = document.getElementById('my_canvas');
var ctx = canvas.getContext('2d');
canvas.width = 320;
canvas.height = 240;
var back = new Image();
var reg = new Image();
var spicy = new Image();
var nosauce = new Image();
var setup1 = setup();
function setup(){
back.src = "selectback.png";
reg.src = "reg.png";
spicy.src = "spicy.png";
nosauce.src = "sauce.png";
back.onload = function(){
ctx.drawImage(back, 0, 0, 321, 241);
};
}
function back(){
var test = new Image();
    test.onload = function() {
        ctx.drawImage(test, 0, 0, 300, 300);
    };
}
window.onload = function () { setup(); }
1
  • 1
    Is it because you have an Image object named back but and also a function called back? Commented Mar 4, 2015 at 2:10

1 Answer 1

1

do this:

document.getElementById('YourIframeId').onload = function() {
setup();
// put your awesome code here
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.