以下代码在 Chrome 中给我一个错误。看起来 window.location.href
没有返回字符串,但这看起来很疯狂。
这是代码:
var theUrl = "" + window.location.href;
var hashValue = theUrl.contains("#") ? theUrl.split('#')[1] : null; (This is line 6)
这会在 Chrome 中返回以下错误:
Uncaught TypeError: Object someUrl#someHash has no method 'contains' myFile.js:6
(anonymous function) faq.js:6
k jquery.min.js:2
l.fireWith jquery.min.js:2
p.extend.ready jquery.min.js:2
D
有什么想法吗?
编辑:也尝试使用document.URL
但无济于事。
最佳答案
目前,String.contains
方法似乎仅受 Firefox 19 支持
String.contains - JavaScript | MDN
该页面还提到了与 MooTools 的一些不兼容性,也许您的问题与之相关。目前您可以像这样检索哈希值
var hashValue = window.location.hash.substr(1) || null;
关于javascript - 对象 someUrl#someHash 没有方法 'contains',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696328/