SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I include JS in a CSS file?

    I'm wondering if I could include a <script> tag in a CSS file so that it gets included into all pages using that CSS file. Is this possible?

  2. #2
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Fionnphort, Isle of Mull, Scotland
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    No, try this

    I doubt if that would work (it hasn't occurred to me to try). What you need is an external JS file (say external.js) which you call from each page with this line in the header '<script type="text/javascript" src="/path/externl.js"></script>'

  3. #3
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, but due to the way permissions are set up at my company (each department owns it's own files), it'd take me all day to go through and add a line to each file. If I could add <script type="text/javascript" src="/path/externl.js"></script> to the css file in each folder, then I save a lot of time.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    CSS is not HTML so you can't add HTML into the CSS file. Script tags are HTML not CSS.
    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="^$">

  5. #5
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Felgall hit the nail on the head. Doesn't your company use server scripts to assemble pages? If so, you should look into an include, which could save you a lot of grief.

  6. #6
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not too sure but i think you can try it with import command....

    @import url("jsfile.js");

    I am not sure but you can try it out.

  7. #7
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Warszawa
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can make it in internet explorer using expression. but I doubt it's possible in other browsers.

  8. #8
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    What you can do, though, is generate a style sheet in Javascript
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  9. #9
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, but wouldn't these methods require me to add lines directly to the html? And I must not know enough about Apache, because I didn't know it assembled the pages. I though it got a request and sent the file to the browser. I'm starting to wonder if I could sudo access somehow and be able to edit and upload all the files without having to change the owner of each one.

  10. #10
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Yes it would, but there's no other way, unless you have some includes you can use.

    I must way, they your company appears to have tried its best to make it as hard as possible for you to do your job.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you thought of adding your script to another script, inserting it into one that is already on every page in the site?????

    Mike

  12. #12
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apache doesn't assemble the pages, scripts in languages like PHP, Ruby, or Perl do. Apache does, usually, provide the support for these languages through the addition of modules.

    Signed in as root (a.k.a. the 'super-user' or su in the console) or in single invocations like sudo, you should be able to access any files in a Linux file system. Some editors will allow you to make modifications to groups of files, so that may offer some potential relief.


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
  •