把获取的 location.href.split("#")[0]; encode一下就行了. var url = encodeURIComponent(location.href.split("#")[0]);