Issues with absolute paths for js files in website
I have a website which has so many sub folders in it. I have following paths references to my js and css files.
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script type="text/javascript" src="js/jquery.js"></script>
the above code is working fine on my local machine. the JS file is not loading when i host the website into production server. Problem in my hosting server is my website is ponted to
www.somewebsitename.com
instead
www.somewebsitename.com/home.aspx
. When I l开发者_开发知识库oad the page with www.somewebsitename.com/home.aspx this url it is loading all the js files it is not loading files only when I load the page with www.somewebsitename.com.
Please solve my problem. How to reference JS files so that they ll loaded how ever u visit the page.
Change:
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script type="text/javascript" src="js/jquery.js"></script>
To:
<link rel="stylesheet" type="text/css" href="/css/styles.css" />
<script type="text/javascript" src="/js/jquery.js"></script>
The leading slashes are a way to say "hey, I'd like you to start from the root of the website and work from there".
So, providing the JS and CSS folders are in the root of the website, it won't matter where you link these files from...sub folders or not, it will always look to the root and work down.
Good luck. Michael.
Have you tried putting a leading slash in front of the paths, so that they are relative to the root folder instead of relative to the HTML folder?
精彩评论