3

My Url is

http://www.domain.com/seg_one/seg_two/seg_three#jumper

I want to get #jumper part of current url

UMDEVELOPER
  • 89
  • 11
  • 6
    Similar to : http://stackoverflow.com/questions/940905/can-i-read-the-hash-portion-of-the-url-on-my-server-side-application-php-ruby – ka_lin Sep 05 '15 at 17:02

4 Answers4

2

In JavaScript, you can get this by simply location.hash property of window object. i.e.

window.location.hash;  // will give you #jumper.

From here once you have it on the client side, do anything you want with it. You can send it back to server by even making an ajax call.

Rohit416
  • 3,416
  • 3
  • 24
  • 41
1

The # is called a fragment. The problem is that browsers won't transmit those to the server so there is now way to parse it.

erikvimz
  • 5,256
  • 6
  • 44
  • 60
1

You can get it via javascript (see below) and make an ajax request to use it in the back-end(PHP):

window.location.href 

You can condition the ajax call:

address = window.location.href;
index = address.str.indexOf("#");
if(typeof index !='null') {
    var term = str.slice(address.str.indexOf("#")+1, address.length);
    console.log(term);//will display jumper
    //send it via AJAX
}
ka_lin
  • 9,329
  • 6
  • 35
  • 56
1
$third = $this->uri->segment(3);
$thirdArr = explode('#', $third);
$hash = $thirdArr[1];
Tpojka
  • 6,996
  • 2
  • 29
  • 39