www.webdeveloper.com
Results 1 to 5 of 5

Thread: Get current path

  1. #1
    Join Date
    Apr 2005
    Posts
    210

    Wink Get current path

    This is my js function:
    Code:
    function navigate_Parameter(num)
    {
    	str = location.href+"?num="+num;
    	location.href=str;
    }
    First time: http ://...../myfile.htm?num=1
    Second time : http ://...../myfile.htm?num=1?num=2
    so on...
    Last time: http ://...../myfile.htm?num=1?num=2........?num=999

    Is there a function to get sole http ://...../myfile.htm without parameters after the link?

    BTW: I don't want to cut full URI to file path.

    .

  2. #2
    Join Date
    Jun 2008
    Posts
    136
    Code:
    function navigate_Parameter(num)
    {
            var placement = location.href.indexOf('?');
            var location_without_parameters = placement == -1 ? location.href : location.href.substr(0, placement);
    
    	str = location_without_parameters+"?num="+num;
    	location.href=str;
    }

  3. #3
    Join Date
    Apr 2005
    Posts
    210
    you are cutting

  4. #4
    Join Date
    May 2012
    Posts
    14
    Try

    str = "http://"+location.host+filePath+"?num="+num;
    location.href=str;

  5. #5
    Join Date
    Mar 2011
    Posts
    1,138
    I'd suggest:
    Code:
    function navigate_Parameter(num)
    {
    	str = location.href.split('?')[0] +"?num="+num;
    	location.href=str;
    }
    Rick Trethewey
    Rainbo Design

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles