SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is my code right?

    I'm trying to add java script to my website so it loads my background image. I followed a tutorial from here, http://thecodecentral.com/2008/02/21...t-image-loader and so I copy and pasted this code into note pad:

    var loader = new ImageLoader('http://www.website.com/htdocs/image.jpg');

    loader.loadEvent = function(url, image){
    //actions to perform when the image is loaded
    //alert(url + ' is loaded');
    document.body.appendChild(image);
    //hide loading indicator if applicable
    }

    loader.load();

    and saved the file as imageloader.js. I didn't put the actual website or image in this post because I don't want it to get referenced when searching my website in google. When I open the page, there is no loader, the image takes a couple seconds to load when you first go to my page like usual. Am I doing something wrong? did I call the file a wrong name? should I reference imageloader.js in the html code of the webpage? Thanks for your time!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by andy1212 View Post
    should I reference imageloader.js in the html code of the webpage?
    yes if you want that web page to run that code.

    <script type="text/javascript" src="imageloader.js"></script>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •