2015-09-05 64 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];