Javascript 无法读取window.location.hash servlet端?
在我的web应用程序中,用户可以单击列表中的项目,我可以在他们的浏览器中修改url:Javascript 无法读取window.location.hash servlet端?,javascript,jsp,servlets,Javascript,Jsp,Servlets,在我的web应用程序中,用户可以单击列表中的项目,我可以在他们的浏览器中修改url: <li>Horse</li> <li>Cow</li> <li>Goat</li> function onListItemClicked() { window.location.hash = item.name; } 马 母牛 山羊 函数onListItemClicked(){ window.location.hash=item
<li>Horse</li>
<li>Cow</li>
<li>Goat</li>
function onListItemClicked() {
window.location.hash = item.name;
}
马
母牛
山羊
函数onListItemClicked(){
window.location.hash=item.name;
}
这将用户浏览器中的url更改为:
www.example.com#Horse
www.example.com#Cow
www.example.com#Goat
如果我读对了,我们就不能得到url servlet端的#部分,对吗?如果用户将url从他们的浏览器复制并粘贴到朋友,如果我可以生成已经用他们单击的项目初始化的页面,那就太酷了
看起来这是不可能的,我必须在文档加载完成后通过javascript加载相应的页面
谢谢不,您不能从服务器端执行此操作。URL片段纯粹是客户端的。在页面加载期间,您需要在客户端执行此操作
window.onload = function() {
var hash = window.location.hash;
// Do your business thing here based on the hash.
}