我的网址是如何从codeigniter中的url跳转到#jumper部分?
http://www.domain.com/seg_one/seg_two/seg_three#jumper
我想当前URL
我的网址是如何从codeigniter中的url跳转到#jumper部分?
http://www.domain.com/seg_one/seg_two/seg_three#jumper
我想当前URL
在JavaScript中,您可以通过简单的location.hash
window
对象的属性获取此对象。即
window.location.hash; // will give you #jumper.
从这里一旦你在客户端有它,就做任何你想要的东西。您甚至可以通过ajax呼叫将其发送回服务器。
我们想要的不是在js中的php – UMDEVELOPER
在你的问题中写到你想在'php'中使用它的地方,除此之外,JS的工作方式也很好。 – Rohit416
在隧道的尽头,最终它的所有'HTML',由'CSS'设计,并由'JS'驱动。 – Rohit416
的#
的#jumper部分称为fragment
。问题是浏览器不会将它们传输到服务器,所以现在有办法解析它。
您可以通过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
}
$third = $this->uri->segment(3);
$thirdArr = explode('#', $third);
$hash = $thirdArr[1];
到类似:http://stackoverflow.com/questions/940905/can-i-read-the-hash-portion-of-the-url-on-my-server-side-application-php -ruby –