Adding script to head with CSS?

Discussion in 'HTML & Website Design' started by krebs, Jul 17, 2011.

  1. #1
    I am trying to add a line of script inside the <head> of every page, however I dont want to go through every page and copy and paste this one line. Is there a way to do this, perhaps with CSS?

    It is the script for google+ and the other social bookmarks. I suppose I could just add the script to the body, but I read its better to have scripts inside the head.

    I tried to find it through other sources but came up dry.
    As always, Thanks in advance for your help.
     
    krebs, Jul 17, 2011 IP
  2. Oxi

    Oxi Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's not necessarily true. Depending on what the script is will depend where it should go inside your markup. If its a stylesheet then of course it should go in the head, when it comes to JavaScript, it's more beneficial to include it just before the end of the body (to increase loading times).

    You cannot add scripts using CSS as its only used for styling a document.

    Depending on your website structure again will depend on the best usage...
    If you are using a CMS like wordpress, adding the script as an external script to the header would of course allow that script to be used on every page.
    If you are using a static website then using a php include/require is the best method.
    If you are running on a host that doesn't support php, than adding the script as an external script before the end of the body is your best bet.
     
    Oxi, Jul 17, 2011 IP
  3. krebs

    krebs Greenhorn

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    Great info there. So I should put it at the end of every page before the end of the body. I can do that with a PHP include. Thanks for your help.
     
    krebs, Jul 17, 2011 IP
  4. jackburd

    jackburd Active Member

    Messages:
    396
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    yes. that's the reason why it's good to use PHP on our websites instead of .html
     
    jackburd, Jul 19, 2011 IP
  5. patrick0001

    patrick0001 Member

    Messages:
    340
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #5
    If your site structure is html, alternatively you can use Dreamweaver template.
     
    patrick0001, Jul 19, 2011 IP