I want to use a JavaScript file, lying in the root folder. How can I include that JS file?
-
Use "JavaScript" or "Javascript" or even "javascript." JavaScript is an implementation of ECMAScript and has nothing to do with Java.user166390– user1663902009-11-03 18:51:18 +00:00Commented Nov 3, 2009 at 18:51
-
Or even "JS" would do. And JScript is another story...Ateş Göral– Ateş Göral2009-11-03 18:52:29 +00:00Commented Nov 3, 2009 at 18:52
-
How do you not know how to do this?Josh Stodola– Josh Stodola2009-11-03 20:27:55 +00:00Commented Nov 3, 2009 at 20:27
Add a comment
|
4 Answers
use
<script language="javascript" src="FILE PATH"></script>
2 Comments
Ateş Göral
The standard way is to use type="text/javascript" instead of the language attribute.
Tarik
Actually
language attribute is used for old browser compatibility but the current modern browsers is now using type="text/javascript"If you need to include the JavaScript from the code behind of a page or WebControl, you have a few options
this.Page.ClientScript.RegisterClientScriptInclude(typeof(WebControlThatNeedsIt), "IdentifierOfTheScriptSuchAsLoad", "~/myfile.js");
this.Page.ClientScript.RegisterClientScriptBlock(typeof(WebControlThatNeedsIt), "IdentifierOfTheScriptSuchAsLoad", "<script type=\"text/javascript\" src=\"/myfile.js\"></script>",false);
If not you can use what Quinton Suggested in the markup.
<script type="text/javascript" src="/myfile.js"></script>
Note that using the
</script>
is important, as self closing doesn't work with script tags i.e.:
<script type="text/javascript" src="/myfilewontwork.js"/>