473,378 Members | 1,544 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,378 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 22859
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: 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.