Tom
Tom

Reputation: 2661

how to include a file which is outside the projectfolder in html/javascript

I usually include my script files like this:

<script type='text/javascript' src="app/scripts/my_script.js"></script> which works fine

as everything lives in the myproject folder. But now I have a file that lives outside, two levels above the project folder:

bigproject/
    --projectjack/
         --myproject/
    --my_other_script.js

I tried including it like this

<script type='text/javascript' src="full/path/to/my_other_script.js"></script>

but it didn't find it as it goes through the myproject folder. It looked it up here: myproject/full/path/to/my_other_script.js

How do I do this?

Thanks

Upvotes: 1

Views: 3838

Answers (2)

Zulfiqar Ali
Zulfiqar Ali

Reputation: 123

My .js file is present at drive 'G:\SecuredFILES' but my .html file present at 'G:\SecuredFILES\Study tutorial\java script tutorial' i use the following path which is working good type="text/javascript" src="G:\SecuredFILES\jquery.js"> Hope so it is enough for your problem

Upvotes: 1

pherris
pherris

Reputation: 17693

You want to reference the root of your bigproject (assuming that is the root) so prepend a slash like /full/path/to/my_other_script.js.

If bigproject is not the root, you can try ../../full/path/to/my_other_script.js but this has the down side of assuming that your project will always be two directories under the bigproject which may not always be the case.

You can read up on paths in other places on SO as well: https://stackoverflow.com/a/21307090/1861459

Upvotes: 2

Related Questions