2013-06-03 251 views
1

我試圖在JavaScript中重新加載之前傳遞一個變量。 如果我用下面的代碼,在location.reload之前傳遞一個變量()

var myUrl = location.href; 
    if (myUrl.substring(myUrl.length-1) == "#") 
    { 
    myUrl = myUrl.substring(0, myUrl.length-1); 
    } 
    myUrl =myUrl+"&abc=Y&bdc=N"; 
    location.href =myUrl;    
    location.reload(); 

這一次,我沒有得到正確的url.ie,我不是在URL獲得&abc=Y&bdc=N。如果我把警報這樣,

var myUrl = location.href; 
if (myUrl.substring(myUrl.length-1) == "#") 
{ 
myUrl = myUrl.substring(0, myUrl.length-1); 
} 
myUrl =myUrl+"&abc=Y&bdc=N"; 
location.href =myUrl; 
alert(location.href); 
location.reload(); 

回答

3

刪除

location.href =myUrl; 
location.reload(); 

只能使用

window.location =myUrl; 
-1

刪除

location.href =myUrl; 
location.reload(); 

只能使用

window.location.href = window.location.href;