0
你好我想檢查用戶是否在特定頁面上,例如:如果他在localhost/chat
顯示他的暱稱。我如何檢查它?如何檢查用戶是否在特定頁面
你好我想檢查用戶是否在特定頁面上,例如:如果他在localhost/chat
顯示他的暱稱。我如何檢查它?如何檢查用戶是否在特定頁面
如果您想在服務器端(使用php
)執行此操作,請查看http://www.php.net/manual/en/reserved.variables.server.php。你可以做這樣的事情:
if($_SERVER['PATH_INFO'] === "/chat") {
// show the name
}
如果你想在客戶端(與javascript
)做到這一點,你可以用location.href
做到這一點。在這裏你可以做這樣的:
if(location.href.split(location.host)[1] === "/chat") {
// show the name
}
使用此代碼...
myUrl = window.location.href; // get the url
lastWordInUrl = myUrl.substring(myUrl.lastIndexOf('/')+1,myUrl.length); // get last word of url
if(lastWordInUrl == 'chat'){...do your stuff...}
但我怎麼能得到用戶名是誰在看這個網頁? – Zolax