Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    External js File For a Background

    Firstly, sorry if my title description is vague but it was the best I could describe my little problem.

    I am creating a new web site and the background for all the pages is going to be the same. I don't want to have to add the background for each page using background properties html code.

    On my last web site I had used a js file which I placed on my server together with a little code on each page which called that js file, similar to the code below:

    Code:
    <script language="javascript" src="background.js"></script>
    The problem is I had gotten rid of the js code and file on the last site and I don't remember what the coding I used was (in particular the coding in the background.js file). If anyone could help me out it would be greatly appreciated.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,616
    Thanks
    0
    Thanked 645 Times in 635 Posts
    The background should be defined in an external stylesheet. There is no need for Javascript to do this as it is appearance and not behaviour that you are trying to define and appearance is defined by the stylesheet (placing it in the HTML is deprecated and is no longer the way to do it).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    The background should be defined in an external stylesheet. There is no need for Javascript to do this as it is appearance and not behaviour that you are trying to define and appearance is defined by the stylesheet (placing it in the HTML is deprecated and is no longer the way to do it).
    How do I go about creating an external stylesheet? I have no experience in using stylesheets but if there's any basics about on the subject I don't mind reading up on it.

  • #4
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here appear to be a few examples...
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #5
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also, here is W3Schools' tutorial on CSS... I noticed that the second example (in the CSS Examples section) goes into how to set a background image!
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!


  •  

    Posting Permissions

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