473,666 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using window.location .pathname

1 New Member
I was trying to capture the pathname only when using

var from= window.location .pathname;

and I want to lose the filename. Is there another way for me to get just the path?
Mar 10 '08 #1
2 10047
rnd me
427 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. function Path() {
  2.     var tob = {href:window.location.href.toString()};
  3.     tob.domain = document.domain;
  4.     var lr = tob.href.toString().split(/[\/\\]/g);
  5.     var tqs = window.location.search;
  6.     tob.qs = tqs ? tqs : "";
  7.     tob.file = lr.last();
  8.     tob.path = lr.slice(0, -1).join("/") + "/";
  9.     tob['char'] = document.characterSet;
  10.     tob.ext = tob.file.match(/(?:\.)[\d\w]{0,4}/)[0];
  11.     return tob;
  12. }
  13. alert(Path().path)
  14.  
  15.  
Mar 10 '08 #2
mrhoo
428 Contributor
or-
var url=location.hr ef.replace(/\\/g,'/');
alert(url.subst ring(0,url.last IndexOf('/')))

(You only need the replace for local files on windows)
Mar 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
8219
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) { document.location.href = document.location.href.substring(0, document.location.href.indexOf('#')) + '?' + newUrl; } else { document.location.href = document.location.href + '?' + newUrl; }
4
2713
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display .="<li>".$wohdate."</li>" ; $TemplateText = Replace($TemplateText,"@$wohdisplayndx@",$woh_display);
10
37848
by: Hughes | last post by:
Hi, I would like to get the filename from a folder by using C language. For example, in path /Users/abc/Desktop/xyz/ there is a file named "test.s" (file "test.s" is inside folder "xyz"). How should I write a routine in C to get the file name "test.s" ? Thanks a lot.
3
5329
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look at it and let me know what I need to change. I have tried changing the "hwnd" type into intptr's but there seem to be other problems too, like it won't allow "lParam As Any" to be declared.
12
7765
by: Don Juan | last post by:
I have a simple html document I have been using for some time on my (i.e.) abc.com domain that uses cookies. I recently purchased a new domain name and set up a service to redirect my new domain (i.e.) xyz.com to a sub-directory of the abc.com domain. In other words, when someone goes to URL xyz.com, they really end up in abc.com/xyz directory but the MSIE browser says they are xyz.com. The problem is that cookies quit working in this...
18
3325
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to the image. The desired behavior is that when the pop-up is invoked, I want the underlying window to stay put. I don't have this problem when I run the code on my local computer but I do have it when I run the code on geocities.
2
2249
by: jwriteclub | last post by:
I have a question regarding back button functionality in an "ajaxy" web application. Here is the scenario: The user navigates to a page http://domain.com/app/. Since app/index.php file contains include this really serves to load app/app.php which is the "ajaxy" application The user loads data and otherwise "does stuff" with app.php At some point, the user reaches a page they would like to be able to send to a friend/coworker/bookmarks...
2
2922
by: find clausen | last post by:
But something like: location.pathname.indexOf I want to check if there in the path is a folder named 'travel' tried this: if (location.pathname.indexOf('travel')) zlang = 1; :-(
0
1329
by: hinchb | last post by:
I have coded a Non-CSS menu using IFRAMES which I would like your opinion on. It seems to work in all the browsers I've tested. Do you see any disadvantages in using something like this. Here is the code. <style> #top { position: absolute; left: 4%;
0
8352
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
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
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...
0
4192
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
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
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
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.