Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript - works in some cases, not in others

Status
Not open for further replies.

sacheson

Programmer
Mar 30, 2000
55
0
0
US
Alright - here's my situation. I'm using ASP.NET 2.0 and some javascript. The jscript works just fine if I put the files in the root directory of the project, and works fine if I upload the .js file to my web server and fully qualify the name in the src attribute of the script tag (meaning:
BUT (here's the bit but(t) of the night) - IF I put the .js file in a "js" folder inside my project on the local machine, ASP does not load the file (or tells me it was loaded with errors in IE).

Thinking it was a permissions issue, I granted every stinking permission to the ASP.NET and IUSR users on my machine. I even wrote some code that opens the files and writes the contents out in my browser - so the application can access it.

Does /anyone/ know what's going on here? What am I not doing? I googled and googled, I searched around this and other forums for about 45 mins before posting this. And I can't find a derned thing. At this point, I'm just dizzy.

FWIW - this is also happening with .css files, so it is repeatable.

______________________________________________
When told, "goto hell", a programmer finds the method, not the destination as harmful.
 
hi,

the SRC path of the JS file will tell the browser where to look for the file.

therefore if the path is set to "

it will not work locally.

rather than doing that try this method:

src="/js/javascriptfilename.js"

/ - Represents the root folder...

Known is handfull, Unknown is worldfull
 
Uhm - I'm doing that. That's my point. Maybe I should explain better ...

1) put myCustomJavascript.js in the root of my project.
example: <script ... src="myCustomJavascript.js">
**** THIS WORKS

2) put myCustomJavascript.js in /any/ folder on my website
example: <script ... src=" **** THIS WORKS

3) place the file in any subdirectory under my project root locally (with all the enumerations I've tried):
example: <script ... src="js/myCustomJavascript.js">
example: <script ... src="../js/myCustomJavascript.js">
example: <script ... src="/js/myCustomJavascript.js">
**** THIS DOES NOT WORK

Also - it works with static html files. It just doesn't seem to work when I execute the code with ASP.NET.

______________________________________________
When told, "goto hell", a programmer finds the method, not the destination as harmful.
 
For server side scripts, try this:
Code:
<script runat="server" src="~/js/myCustomJavascript.js" type="text/javascript">

Sharing the best from my side...

--Prashant--
 
>>Also - it works with static html files. It just doesn't seem to work when I execute the code with ASP.NET.

open the ASPX file in the browser. do a view source of the outputted HTML.

try to fint the <script> tag. is it the same as what you had entered???

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top