Can't use external JavaScript file if in different directory
Posted by: rainandstorm (129.42.208.---)
Date: February 14, 2013 01:21AM

In my webroot (i.e. C:\wamp\www) I have the folders alpha and bravo. A JavaScript file named aScript.js is in alpha and an HTML file called user.html is in bravo. I reference the external JavaScript by

<script type="text/javascript" src="../alpha/aScript.js">

but whenever I call a function in it the browser console says the function is not defined. If I copy and past the exact same files onto the desktop it works fine. Does WAMP have some permissions I must change? I haven't set up any of my own .htaccess files

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: RiggsFolly (---.as13285.net)
Date: February 14, 2013 10:59AM

You need to close the tag

<script type="text/javascript" src="../alpha/aScript.js"></script>

Not sure this is a good practice though as these 2 folders should function like seperate sites and have all their resources under the same folder.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: rainandstorm (129.42.208.---)
Date: February 14, 2013 06:19PM

It was closed I just didn't include it in the post.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: RiggsFolly (---.as13285.net)
Date: February 14, 2013 11:17PM

Well it works when you have it coded correctly and you have apache configured properly. So something else must be wrong.

if you want I can TeamViewer in to your system and have a look.

If you want to do this install team Viewer ( its free for casual use ) and send me a Private message with the ID and Password.
I am on GMT and an available now for an hour or so, or tomorrow.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: rainandstorm (129.42.208.---)
Date: February 18, 2013 10:17PM

RiggsFolly Wrote:
-------------------------------------------------------
> Well it works when you have it coded correctly and
> you have apache configured properly. So something
> else must be wrong.
>
> if you want I can TeamViewer in to your system and
> have a look.
>
> If you want to do this install team Viewer ( its
> free for casual use ) and send me a Private
> message with the ID and Password.
> I am on GMT and an available now for an hour or
> so, or tomorrow.

Did you get my private message? I thought I sent it but my sent folder is empty.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: February 19, 2013 01:40PM

Are you sure this is not just your cross site scripting filter denying the load of a script from another site.

That is basically what you are doing, loading a script from another site.

Try placing the script in the bravo folder and loading it from there, see if it runs then.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: rainandstorm (129.42.208.---)
Date: February 19, 2013 06:10PM

RiggsFolly Wrote:
-------------------------------------------------------
> Are you sure this is not just your cross site
> scripting filter denying the load of a script from
> another site.
>
> That is basically what you are doing, loading a
> script from another site.
>
> Try placing the script in the bravo folder and
> loading it from there, see if it runs then.

Yes it does run if they are both in bravo. The thing that surprised me is it seems to work ok if the directories are on the desktop but as soon as they are in the WAMP directory it doesn't work.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: February 19, 2013 06:24PM

By on the desktop do you mean you put a folder on the desktop and run the html files by doulble clicking on xyz.html using explorer??


If that the case it works because you are not actually going through a web server soing it that way.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: rainandstorm (129.42.208.---)
Date: February 19, 2013 08:31PM

Yes. Also I tried putting them in the WAMP web root folder.

For example in my browser if I go to localhost/bravo/xyz.html no javascript works but if I go to c:\wamp\www\bravo\xyz.html javascript works fine

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: stevenmartin99 (Moderator)
Date: February 19, 2013 08:43PM

can you send me teamviewer details, this is just a mistake your making, it has nothign to do with wamp

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: February 19, 2013 09:05PM

I have just done it Steve.

Options: ReplyQuote
Re: Can't use external JavaScript file if in different directory
Posted by: stevenmartin99 (Moderator)
Date: February 19, 2013 09:16PM

what was the issue?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote


Sorry, only registered users may post in this forum.