473,836 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 22884
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(tar get) 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.s ubstring(0,loca tion.href.lastI ndexOf("/")+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(tar get) 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.s ubstring(0,loca tion.href.lastI ndexOf("/")+1);

or

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

:-p

--
Rob

Jul 23 '05 #5

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

Similar topics

31
3942
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 in the os module got objectified properly (or at least with some semblance of OO propriety!) In the issues section:
9
3608
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
4130
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 Python standard library, and Reinhold Birkenfeld started a discussion on it in python-dev <http://mail.python.org/pipermail/python-dev/2005-June/054438.html>. The upshot of the discussion was that many python-dev'ers wanted path added to the...
34
3276
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: /python/nondist/sandbox/path/{path.py,test_path.py} One thing is still different, though: a Path instance won't compare to a regular string.
2
23393
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 using '/' as delimiters and get the last 'word'. The reason I'm not entirely happy with that method is that it is platform specific. I would prefer to use a built in method if possible. Cheers,
1
5863
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 the no funny business can go on in the passed "path" that would produce a path not in the root (i.e. "..\..\dir1"). Here is my first stab at it, but not sure if this is too much or not enouph to ensure this. Any thoughts are welcome. TIA. ///...
4
3256
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 Windows XP using Python 2.5.2 I get the following traceback:
34
5381
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 "<pyshell#10>", line 1, in <module> os.startfile("C:\Documents and Settings\Alex\My Documents\My
8
11533
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 file. each control has a border with another style, and each border has a unique path inside of it. I need to dynamically add these content controls using c# at runtime and am having trouble referencing the styles and adding the path into the...
6
4063
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, realpath, abspath here = dirname(realpath(abspath(__file__.rstrip("c")))) In particular, this takes care of the case of symlinked, compiled scripts, which is fairly common at my workplace, and I imagine in many *nix evironments.
0
9672
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10854
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5652
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4460
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.