2012-10-03 40 views

回答

1

这里,试试这个:

window.location = String(window.location).match(/(.*?)\?/)[1]; 

或者在评论

window.location = "http://localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx?date=20-Sep-2012%22".match(/(.*?)\?/)[1]; 
+0

其不工作... – user1619874

+0

好吧,你有一个例子,我可以看看? –

+0

这是我想要修改的url“http:// localhost:2314/RewardPointsSystem/Admin/PointCalculations.aspx?date = 2012年9月20日”我想用url加载我的页面“http:// localhost: 2314/RewardPointsSystem/Admin/PointCalculations.aspx“当我点击按钮 – user1619874

2

使用例如URL尝试

var query = window.location.href.match(/^(.*)\?/); 
if (query){ 
    history.pushState(null, "", query[1]); 
} 
+0

感谢您的回复...但它不工作 – user1619874

+0

@ user1619874这只会在支持pushState的浏览器,即不是,即 – Musa

+0

你忘了提及这是一个HTML5只有特点。 https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries –

0

你可以只修剪整个字符串后面的“? “标记

2

你不能简单地删除查询字符串,而无需重定向或重新加载页面。所以你会改变位置或使用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 
相关问题