2014-01-18 51 views

回答

1

如果您想在服務器端(使用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 
} 
+0

但我怎麼能得到用戶名是誰在看這個網頁? – Zolax

0

使用此代碼...

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...} 
相關問題