SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Farmington
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    for a start try this
    Code JavaScript:
    var url = document.location.toString();
    var chunks = url.split('/');
    var newUrl = chunks.slice(0,chunks.length -2).join('/');
    alert(newUrl)

    Bye

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Farmington
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I was able to come up with the code that worked. But your code is more elegant and I would use that.

    Code:
    var url_string = String(document.location).toString();
    var url_string_array = url_string.split('/',5);
    var siteCollName = url_string_array[4];
    var siteCollNameLen = siteCollName.length;
    var siteNamePos = url_string.indexOf(siteCollName);
    var url_desired_string = url_string.substring(0,siteNamePos+siteCollNameLen+1);
    
    alert(url_desired_string);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •