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.

6
  • 2
    If you are using web-server than these links are not acceptable Commented Nov 2, 2015 at 13:08
  • 2
    The "link" is a url. If you can't see it though the web browser then it won't work. You will need to put your css/js into a folder in your web site, not the desktop Commented Nov 2, 2015 at 13:10
  • 2
    The second one should use <script> tag, not <link>. Commented Nov 2, 2015 at 13:11
  • Also, use <script> instead of <link> for including JS. Commented Nov 2, 2015 at 13:11
  • Thank you @ManojKumar fuyushimoya. Commented Nov 2, 2015 at 14:33

1 Answer 1

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"/>
Sign up to request clarification or add additional context in comments.

3 Comments

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.
Absolutely right @Liam, the absolute filesystem path has been added for completeness, but typically is unusefull.
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.