Jump to content

getting a js file from different directory


Web Weenie
 Share

Recommended Posts

I have a directory for all my external javascripts and call it js. This directory resides on the same level as all my main html (home). I also have a directory of html pages that are meant to insert into an iframe called inventory. This directory also resides in the home level. These pages need to access a js script that is in my js directory. if I place the js inside my inventory directory - it works and I use this;<script type="text/javascript" src="dltable.js">I expected one of these to work when the script is in my js directory - no workie!<script type="text/javascript" src="..js/dltable.js"><script type="text/javascript" src="../js/dltable.js">Can someone please explain how to properly access a file that resides in a different directory. I guess this is another thing for my things I thought I knew, list!Do I need a preceding slash or something?TIA

Edited by Web Weenie
Link to comment
Share on other sites

It depends on what your file structure looks like."../" moves up one directory. If you're in the "html/" directory and on the same level is a "scripts/" directory, you have to write "../scripts/" to access it.

Link to comment
Share on other sites

It depends on what your file structure looks like."../" moves up one directory. If you're in the "html/" directory and on the same level is a "scripts/" directory, you have to write "../scripts/" to access it.
Ok, that's what I thought, so something is wrong...Just to clarify; I have this structurehome = html directory where my main html files are, including index.htmlhome/js/dltable.js = where my external javascripts arehome/inventory/inv0001.html = this file needs to access home/js/dltable.jsDo I need to use the full path or is there a problem accessing a js from a different directory?This doesn't work??? <script type="text/javascript" src="../js/dltable.js"> Edited by Web Weenie
Link to comment
Share on other sites

This should work if the file structure is as you described:<script type="text/javascript" src="../js/dltable.js"></script>If it's not working then one of the files might not be where you think they are.

Link to comment
Share on other sites

This should work if the file structure is as you described:<script type="text/javascript" src="../js/dltable.js"></script>If it's not working then one of the files might not be where you think they are.
Ok, I'm a bit redfaced on this one... Yes, it is working...I was testing locally on my desktop and I guess there is a problem doing this like that. Once I uploaded the js file and the page that calls it, it worked fine. There's a few hours I'll never get back...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...