2012-10-03 41 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 
相關問題