Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute path in JavaScript script tag

Is there an absolute path while declaring the tag?

this will resolve if I have a aspx page in a folder (one level) script src="../Scripts/jquery-1.4.1.js" type="text/javascript">

this will resolve if I have a aspx page in a folder (two level) script src="../../Scripts/jquery-1.4.1.js" type="text/javascript">

this will resolve if I have a aspx page in the main root script src="Scripts/jquery-1.4.1.js" type="text/javascript">

Do i really need to create different version for each relative path?

like image 759
user384080 Avatar asked Aug 18 '10 05:08

user384080


People also ask

How do you create an absolute path in JavaScript?

import * as file4 from './file4'; An absolute import path is a path that starts from a root, and you need to define a root first. In a typical JavaScript/TypeScript project, a common root is the src directory. For file1.

How do you put a file path in script tag?

To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.

What is script src in HTML?

The src attribute specifies the URL of an external script file. If you want to run the same JavaScript on several pages in a web site, you should create an external JavaScript file, instead of writing the same script over and over again. Save the script file with a .

What is script tag in JavaScript?

The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.


1 Answers

You may want to use a relative path from the domain root instead:

<script src="/Scripts/jquery-1.4.1.js" type="text/javascript">
like image 185
Daniel Vassallo Avatar answered Sep 23 '22 11:09

Daniel Vassallo