1

I'm trying to link manually my CSS and Javascript files to my HTML scripts, but I've never really done it with files from a different folder/directory. This is what I have so far:

<link rel="stylesheet" type="text/css" href="/Desktop/Script/CSS/tempeststyle.css"/>
<link rel=script" type="text/javascript" href="/Desktop/Script/Javascript/tempestscript.js"/>

I've read from a few sources that you don't have to start all the way at C:/Users or whatever the case may be for different systems, but I'm not sure if these links are acceptable the way they are (i.e., them starting at "/Desktop"). The files are in separate folders within the same folder on the desktop. So how to include them the best way? Thanks.

morels
  • 2,095
  • 17
  • 24
Phil C.
  • 114
  • 1
  • 12

1 Answers1

3

If you want to add scripts from local path you can use a relative path:

<link rel="stylesheet" type="text/css" href="../CSS/tempeststyle.css"/>

or relative path from your web root folder:

<link rel="stylesheet" type="text/css" href="/styles/CSS/tempeststyle.css"/>

or filesystem absolute path:

<link rel="stylesheet" type="text/css" href="file:///C:/Path/To/Scripts/styles/CSS/tempeststyle.css"/>

It is rather better if you use an absolute path from your web server:

<link rel="stylesheet" type="text/css" href="http://www.example.com/styles/CSS/tempeststyle.css"/>
morels
  • 2,095
  • 17
  • 24
  • 1
    Be careful with the `file://` this looks for the file on the browser(client) **not the server**! So unless the person browsing your site has this file locally (which is very unlikely 99% of the time) they will not get the relevant css/js. Typically this would not be used. – Liam Nov 02 '15 at 13:18
  • Absolutely right @Liam, the absolute filesystem path has been added for completeness, but typically is unusefull. – morels Nov 02 '15 at 13:25
  • Would you guys be able to elaborate a bit on how to find/create the absolute path from a webserver, or maybe point me somewhere that would help? – Phil C. Nov 02 '15 at 14:40