how to include javascript into web app projet in visual studio?
Anyone knows how to include javascript file as project's resource for aspx.cs files under differe开发者_如何转开发nt folders to use?thanks very much
Suppose your project's directory looks like:
/App_Code
/App_Data
/App_Themes
/Master_Pages
...
web.config
Add a folder called "scripts" so you have:
/App_Code
/App_Data
/App_Themes
/Master_Pages
/scripts
...
web.config
Put your javascript file in this scripts folder.
Put the script tag in any of your aspx pages.
<script src="/ProjectRoot/scripts/your-file.js" type="text/javascript"></script>
The key to remember is the path you specify in the src attribute. This is relative to the root of your domain. If you are developing on your machine and you test your project at: http://localhost:2430/SomeProject/
Then your script tag needs to look like:
<script src="/SomeProject/scripts/your-file.js" type="text/javascript"></script>
If your project is deployed on a server at the root: http://www.example.com/
Then your script tag needs to look like:
<script src="/scripts/your-file.js" type="text/javascript"></script>
If your project is deployed on a server at the root: http://www.example.com/SomeApp
Then your script tag needs to look like:
<script src="/SomeApp/scripts/your-file.js" type="text/javascript"></script>
FYI, because the script tag is not a server-side tag you can't use the "~/" syntax. And because you can't use the "~/" syntax, you (usually) can't use a relative path for the src attribute but instead have to specify an absolute path from the root of your domain.
Put the javascript file in a folder in the web application project.
In pages where you want to refer the javascript file you can add this in your aspx file.
<script src="path_to_yourfile" type="text/javascript"></script>
精彩评论