Question

This seems like a rather dumb question to ask but I would like to resolve this quickly and start working.I have a folder in which my html resides and I have the javascript files in a seperate folder called js.I have tried to add the script like this:

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

and I have also tried like this:

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

I have even tried like this:

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

As far as I understand either of the first two should work:

 / root folder
./ current folder
../one folder up

The paths of the files are

 /home/anr/Desktop/maps/server/client/js/gmaps.js
 /home/anr/Desktop/maps/server/client/google_maps.html

UPDATE:

The js file has window.onload and it also creates another script tag programmatically and adds it to the dom,after moving to the external script file I find that the map does not load

Was it helpful?

Solution 2

Be sure that you are closing your tag as well. Once you have the correct relative path, your syntax should be:

<script type="text/javascript" src="relative_path_here"></script>

The following link could be helpful for setting the relative path in HTML: Basic HTML - how to set relative path to current folder?

OTHER TIPS

Looks like you just need to close your script tag with a on the first example, which should work.

Try this,

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

The script tag should be closed

<script type="text/javascript" src="js/gmaps.js"></script> Tag should be closed

I also had a similar problem but not with the path. My problem is the encoding of the html file in my demo, change encoding to ASNI to fix problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top