473,382 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How can I get my Path?

Is there a javascript variable that contains the path of the file from which
it ran?

Something like this....?
alert('My path=' + MyURLPath);

Is this possible?
Jul 23 '05 #1
4 22860
Lee
Keith Smith said:

Is there a javascript variable that contains the path of the file from which
it ran?

Something like this....?
alert('My path=' + MyURLPath);


alert(location.href);
Some code may be loaded into the page from other URL's, but
Everything in a web page "runs" from the URL in location.href.

Jul 23 '05 #2
> alert(location.href);

Thanks for the solution. I noticed that the above method gives me the URL
path with the file name at the end. For example, it may give me something
like http://www.domain.com/pictures/file1.html.

Is there a way to have it give me the URL and path without the file? For
example:
http://www.domain.com/pictures/?

Jul 23 '05 #3
Lee
Keith Smith said:
alert(location.href);


Thanks for the solution. I noticed that the above method gives me the URL
path with the file name at the end. For example, it may give me something
like http://www.domain.com/pictures/file1.html.

Is there a way to have it give me the URL and path without the file? For
example:
http://www.domain.com/pictures/?


Since location.href is a string, you can use the String methods.
http://docs.sun.com/source/816-6408-10/string.htm

The lastIndexOf(target) method returns the index of the last occurance
of <target> within the string.

The substring(first,last) returns the <first> through <last> characters
of the string.

Combining these:

var myURL = location.href.substring(0,location.href.lastIndexO f("/")+1);

Jul 23 '05 #4
Lee wrote:
Keith Smith said:
alert(location.href);
Thanks for the solution. I noticed that the above method gives me the URLpath with the file name at the end. For example, it may give me somethinglike http://www.domain.com/pictures/file1.html.

Is there a way to have it give me the URL and path without the file? Forexample:
http://www.domain.com/pictures/?


Since location.href is a string, you can use the String methods.
http://docs.sun.com/source/816-6408-10/string.htm

The lastIndexOf(target) method returns the index of the last

occurance of <target> within the string.

The substring(first,last) returns the <first> through <last> characters of the string.

Combining these:

var myURL =

location.href.substring(0,location.href.lastIndexO f("/")+1);

or

var myURL = location.href.match(/^.*\//);

:-p

--
Rob

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: John Roth | last post by:
I'm adding a thread for comments on Gerrit Holl's pre-pep, which can be found here: http://tinyurl.com/2578q Frankly, I like the idea. It's about time that all of the file and directory stuff...
9
by: Bengt dePaulis | last post by:
I have a local directory that I want to include in my sys.path How to save it permanently? Regards /Bengt
70
by: Michael Hoffman | last post by:
Many of you are familiar with Jason Orendorff's path module <http://www.jorendorff.com/articles/python/path/>, which is frequently recommended here on c.l.p. I submitted an RFE to add it to the...
34
by: Reinhold Birkenfeld | last post by:
Hi, the arguments in the previous thread were convincing enough, so I made the Path class inherit from str/unicode again. It still can be found in CVS:...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
1
by: William Stacey [MVP] | last post by:
I need a bullet proof way to combine a root and a relative path to form a FQ rooted path (similar to a VDir in IIS). Path.Combine alone will not do the job in all cases. I also need to be sure...
4
by: python | last post by:
Bad file names, i.e. filenames the OS considers illegal, will cause functions in the os.path module to raise an error. Example: import os.path print os.path.getsize( 'c:/pytest/*.py' ) On...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
8
by: moondaddy | last post by:
I'm posting code for a user control ( FunctionConnectorSelector) below which has 3 content controls in it. each content control uses a style from a resource dictionary merged into the app.xaml...
6
by: bukzor | last post by:
I have to go into these convulsions to get the directory that the script is in whenever I need to use relative paths. I was wondering if you guys have a better way: from os.path import dirname,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.