2015-09-05 62 views

回答

1

在JavaScript中,您可以通过简单的location.hashwindow对象的属性获取此对象。即

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

从这里一旦你在客户端有它,就做任何你想要的东西。您甚至可以通过ajax呼叫将其发送回服务器。

+0

我们想要的不是在js中的php – UMDEVELOPER

+1

在你的问题中写到你想在'php'中使用它的地方,除此之外,JS的工作方式也很好。 – Rohit416

+0

在隧道的尽头,最终它的所有'HTML',由'CSS'设计,并由'JS'驱动。 – Rohit416

0

#的#jumper部分称为fragment。问题是浏览器不会将它们传输到服务器,所以现在有办法解析它。

0

您可以通过JavaScript(见下文)得到它,使Ajax请求在后端使用它(PHP):

window.location.href 

可以调理Ajax调用:

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 
} 
0
$third = $this->uri->segment(3); 
$thirdArr = explode('#', $third); 
$hash = $thirdArr[1];