获取去location.hash的一个问题

获取去location.hash的一个问题

谈论这个的好像不是特别多,应用场景比如想gmail,google reader这样的Ajax应用,会将参数放在#后面, https://www.google.com.hk/reader/view/#stream/xxxxx

在这里如果直接取location.hash是没问题的

console.log(location.hash)
//-> #stream/xxxxx

当hash后面还有带?的参数的时候,比如 https://www.google.com.hk/reader/view/#stream/xxxxx?lang=zh_c

console.log(location.hash)
/* 
期望的结果是
#stream/xxxxx?lang=zh_c
但是ie6下面只能取到
#stream/xxxxx
*/

所以,用location.hash来取hash值是不够安全的。

解决办法是通过location.href将整个url取出,然后再从url中解析出hash值

Author: tom

Date: 2012-08-22 21:43:27 CST

HTML generated by org-mode 6.33x in emacs 23

posted on 2012-08-22 21:46  wewe.Tom  阅读(331)  评论(0编辑  收藏  举报