安卓微信浏览器中window.location.href失效的问题
存在问题:
在微信浏览器中,使用window.location.href,会发现在android手机上来回切换会导致跳转不成功。iOS却能正常跳转。
原因:
在手机WEB端,click事件会有 200~300 ms的延迟时间,所以请用tap或者touch代替click作为点击事件。
解决方案:
在window.location.href=url后面加上一个时间戳,即动态获取的一个时间参数。
即,将window.location.href=url改为window.location.href=url?+时间参数
eg: window.location.href = url + ‘?v=’ + (new Date().getTime())
js解码与转码
escape() 来编码字符串
encodeURI() 可把字符串作为 URI 进行编码
提示:如果 URI 组件中含有分隔符,比如 ? 和 #,则应当使用 encodeURIComponent() 方法分别对各组件进行编码
unescape() 解码
**decodeURI()**解码
decodeURIComponent() 解码
location.reload和location.replace的区别
location.reload([bForceGet])
该方法强迫浏览器刷新当前页面
location.replace(URL)
该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来访问已经被替换的URL
跳转页面
window.location.href = url
URL 的协议部分
window.location.protocol (http: 或者 https:)
URL 的主机部分
window.location.host (mp.csdn.net 或者 www.baidu.com)
URL 的端口部分
window.location.port (’’=80)
URL 的路径
window.location.pathname (/mdeditor/88861339)
查询(参数)部分 (?之后的参数且包含?)
window.location.search (?sid=1&search=lu)
锚点
window.location.hash (#imhere)