using the ~/ path with script files?

M

Milsnips

hi there,

i'm currently using the following line:

<script language="javascript" type="text/javascript"
src="../scripts/timer.js"></script>

but i want to do the following, as the script needs to be used in many pages
at varios folder depths ( it is placed in my master page).

<script language="javascript" type="text/javascript"
src="~/scripts/timer.js"></script>

doesnt ASP.NET 2.0 pick up that i've put the "~/" symbol in the script SRC
parameter, as it only works on the pages within the SRC root "../" which im
currently using.

any help appreciated.

thanks,
Paul.
 
L

Laurent Bugnion [MVP]

Hi,
hi there,

i'm currently using the following line:

<script language="javascript" type="text/javascript"
src="../scripts/timer.js"></script>

The "language" attribute has been deprecated, and you should remove it.
but i want to do the following, as the script needs to be used in many pages
at varios folder depths ( it is placed in my master page).

<script language="javascript" type="text/javascript"
src="~/scripts/timer.js"></script>

<script type="text/javascript"
src="/scripts/timer.js"></script>

This looks for the "scripts" folder at the root of the website.

HTH,
Laurent
 
M

Milsnips

hi Laurent,

it isnt solving my problem, this is the folder heirarchy i have, and where
my javascript works and doesnt


ROOT
SCRIPTS/
timer.js
TEMPLATES/
main.master - with following line: <script
type="text/javascript" src="../scripts/timer.js"></script>
EN/
projects.aspx - javascript works on this file.
PROJECTS/
active.aspx - javascript DOESNT work here..
completed.aspx - javascript also DOESNT work here..


I hope you understand the folder heirarchy i;ve done, the BOLD items are
folders

regards,
Paul

Laurent Bugnion said:
Hi,
hi there,

i'm currently using the following line:

<script language="javascript" type="text/javascript"
src="../scripts/timer.js"></script>

The "language" attribute has been deprecated, and you should remove it.
but i want to do the following, as the script needs to be used in many
pages at varios folder depths ( it is placed in my master page).

<script language="javascript" type="text/javascript"
src="~/scripts/timer.js"></script>

<script type="text/javascript"
src="/scripts/timer.js"></script>

This looks for the "scripts" folder at the root of the website.

HTH,
Laurent
doesnt ASP.NET 2.0 pick up that i've put the "~/" symbol in the script
SRC parameter, as it only works on the pages within the SRC root "../"
which im currently using.

any help appreciated.

thanks,
Paul.
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
L

Laurent Bugnion [MVP]

Hi,
hi Laurent,

it isnt solving my problem, this is the folder heirarchy i have, and where
my javascript works and doesnt


ROOT
SCRIPTS/
timer.js
TEMPLATES/
main.master - with following line: <script
type="text/javascript" src="../scripts/timer.js"></script>

I think I suggested src="/scripts/timer.js"

The masterpage is a control. The path to the "scripts" folder is
relative to the page (ASPX), *not* to the master.

My suggestion is an absolute path pointing to the "scripts" folder in
the website root. I still think it should work.

HTH,
Laurent
 
G

Guest

Hi there,

Try this one:

<script language="javascript" src="<%=ResolveClientUrl("~/scripts/timer.js")
%"></script>

or in master page load event

Page.ClientScript.RegisterClientScriptInclude("timerScript",
ResolveClientUrl("~/scripts/timer.js"));


--
Milosz


Milsnips said:
hi Laurent,

it isnt solving my problem, this is the folder heirarchy i have, and where
my javascript works and doesnt


ROOT
SCRIPTS/
timer.js
TEMPLATES/
main.master - with following line: <script
type="text/javascript" src="../scripts/timer.js"></script>
EN/
projects.aspx - javascript works on this file.
PROJECTS/
active.aspx - javascript DOESNT work here..
completed.aspx - javascript also DOESNT work here..


I hope you understand the folder heirarchy i;ve done, the BOLD items are
folders

regards,
Paul

Laurent Bugnion said:
Hi,
hi there,

i'm currently using the following line:

<script language="javascript" type="text/javascript"
src="../scripts/timer.js"></script>

The "language" attribute has been deprecated, and you should remove it.
but i want to do the following, as the script needs to be used in many
pages at varios folder depths ( it is placed in my master page).

<script language="javascript" type="text/javascript"
src="~/scripts/timer.js"></script>

<script type="text/javascript"
src="/scripts/timer.js"></script>

This looks for the "scripts" folder at the root of the website.

HTH,
Laurent
doesnt ASP.NET 2.0 pick up that i've put the "~/" symbol in the script
SRC parameter, as it only works on the pages within the SRC root "../"
which im currently using.

any help appreciated.

thanks,
Paul.
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
M

Milsnips

Thanks Milosz,

thats just the kind of solution i was looking for, and it works great!
Thanks to all the resfponses rom the others also :)

regards,
Paul
Milosz Skalecki said:
Hi there,

Try this one:

<script language="javascript"
src="<%=ResolveClientUrl("~/scripts/timer.js")
%"></script>

or in master page load event

Page.ClientScript.RegisterClientScriptInclude("timerScript",
ResolveClientUrl("~/scripts/timer.js"));


--
Milosz


Milsnips said:
hi Laurent,

it isnt solving my problem, this is the folder heirarchy i have, and
where
my javascript works and doesnt


ROOT
SCRIPTS/
timer.js
TEMPLATES/
main.master - with following line: <script
type="text/javascript" src="../scripts/timer.js"></script>
EN/
projects.aspx - javascript works on this file.
PROJECTS/
active.aspx - javascript DOESNT work here..
completed.aspx - javascript also DOESNT work
here..


I hope you understand the folder heirarchy i;ve done, the BOLD items are
folders

regards,
Paul

Laurent Bugnion said:
Hi,

Milsnips wrote:
hi there,

i'm currently using the following line:

<script language="javascript" type="text/javascript"
src="../scripts/timer.js"></script>

The "language" attribute has been deprecated, and you should remove it.


but i want to do the following, as the script needs to be used in many
pages at varios folder depths ( it is placed in my master page).

<script language="javascript" type="text/javascript"
src="~/scripts/timer.js"></script>

<script type="text/javascript"
src="/scripts/timer.js"></script>

This looks for the "scripts" folder at the root of the website.

HTH,
Laurent


doesnt ASP.NET 2.0 pick up that i've put the "~/" symbol in the script
SRC parameter, as it only works on the pages within the SRC root "../"
which im currently using.

any help appreciated.

thanks,
Paul.
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top