我想从我当前的页面url中删除查询字符串在JavaScript上的按钮单击 可以帮我使用上面的代码。从javascript中的当前页面url中删除查询字符串
回答
这里,试试这个:
window.location = String(window.location).match(/(.*?)\?/)[1];
或者在评论
window.location = "http://localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx?date=20-Sep-2012%22".match(/(.*?)\?/)[1];
使用例如URL尝试
var query = window.location.href.match(/^(.*)\?/);
if (query){
history.pushState(null, "", query[1]);
}
感谢您的回复...但它不工作 – user1619874
@ user1619874这只会在支持pushState的浏览器,即不是,即 – Musa
你忘了提及这是一个HTML5只有特点。 https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries –
你可以只修剪整个字符串后面的“? “标记
你不能简单地删除查询字符串,而无需重定向或重新加载页面。所以你会改变位置或使用windows.location重定向。 getPathFromUrl()函数从给定的URL中移除查询字符串。
下面是例U怎么能做到这一点:
function getPathFromUrl(url) {
return url.split("?")[0];
}
var testurl='http://localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx?date=20-Sep-2012%22'
window.location=getPathFromUrl(testurl); // loads http://localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx
- 1. 从URL中删除查询字符串
- 2. 在页面刷新之前从URL中删除查询字符串
- 3. 如何从c#2.0中删除当前网页查询字符串的查询字符串的特殊列表
- 4. 从URL段删除查询字符串
- 5. 从网址中删除页面+查询字符串
- 6. 使用javascript从字符串(URL)中删除子字符串(URL)
- 7. Apache mod_rewrite页面前的查询字符串,并删除扩展
- 8. 如何在页面加载后从url中删除查询字符串?
- 9. Zend Framework:将查询字符串追加到当前页面url
- 10. 从查询字符串中删除值
- 11. 从asp.net中删除查询字符串
- 12. 如何从url中删除空的查询字符串?
- 13. 从URL中删除特定的查询字符串
- 14. 从url中删除特定的查询字符串参数值
- 15. 获取当前url查询字符串
- 16. 如何在javascript中从url中删除查询字符串数组
- 17. 无法使用.htaccess从URL中删除查询字符串
- 18. 从url中删除index.php和index.php查询字符串
- 19. 从url中删除整个查询字符串?
- 20. 如何从url中删除查询字符串参数?
- 21. 如何从url中删除查询字符串?
- 22. 通过mod重写从url中删除查询字符串
- 23. mod_rewrite:从URL中删除查询字符串?
- 24. htaccess - 重定向查询字符串,并从URL中删除它
- 25. mod_rewrite:从URL的末尾删除查询字符串URL
- 26. 刷新前查询字符串删除
- 27. 如何在ajax页面中查询查询字符串或URL?
- 28. 从字符串中删除前面的字符?
- 29. 如何从查询字符串参数(Crosscripting)中删除javascript?
- 30. Zend从分页查询字符串中删除参数
其不工作... – user1619874
好吧,你有一个例子,我可以看看? –
这是我想要修改的url“http:// localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx?date = 2012年9月20日”我想用url加载我的页面“http:// localhost: 2314/RewardPointsSystem/Admin/PointCalculations.aspx“当我点击按钮 – user1619874