2015-09-14 38 views
0

我需要從url中刪除值後?在接下來的頁面中,我點擊我的第一頁。我嘗試了很多編碼,但無法走上儀式。需要幫忙。 字符串ex,Name,JobTitle和Date是動態生成的ref值。 下面是與代碼相關鏈接:使用javascript僅刪除下一頁中的url參數值

提供網址

文件:/// C:/Users/varun.singh/Desktop/www%20updated%2027.8.2015%20Old/ WWW /考生/ newOne.html?

合力網址:

文件:/// C:/Users/varun.singh/Desktop/www%20updated%2027.8.2015%20Old/www/Candidates/newOne.html ?名稱=名稱%201 & JOBTITLE =標題%201 &日期=進入%20Date%201

listItem.onclick = function(){ 


     var elementData=listData[this.id]; 
     var stringParameter= "Name=" + elementData.name +"&JobTitle="+elementData.job_title+"&Date="+ elementData.entered_date; 

     //window.location.href = window.location.href.replace("ListCandidateNew", "newOne") + "?" + stringParameter; 
     window.location.href="file:///C:/Users/varun.singh/Desktop/www%20updated%2027.8.2015%20Old/www/Candidates/newOne.html?" 
       + stringParameter; 
} 
+0

[從URL中刪除查詢字符串]的可能重複(http://stackoverflow.com/questions/2540969/remove-querystring-from-url) – GiamPy

+0

剛剛刪除'+ stringParameter;'從href –

+0

您用於維護URL的apporch是錯誤的。儘量保持使用相對URL。 –

回答

0

這應該工作:

var url = file:///C:/Users/varun.singh/Desktop/www%20updated%2027.8.2015%20Old/www/Candidates/newOne.html?Name=Name%201&JobTitle=Title%201&Date=Entered%20Date%201 

    var index = url.lastIndexOf("?"); 

    url = url.slice(0, index+1); // index+1 so that "?" is included 
0

感謝everond嘗試和嘗試回答我的問題。那麼,我已經找到了使用window.sessionStorage的解決方案,因爲我希望通過保持字符串參數可以傳遞值。下面是完整的代碼:

我從一個傳遞值到另一個兩頁:ListCandidateNew.html和newOne.html

ListCandidateNew.html

listItem.onclick = function() 
 
\t \t \t \t \t \t { \t 
 
\t \t \t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t \t \t var elementData=listData[this.id]; 
 
\t \t \t \t \t \t var stringParameter= "Name=" + elementData.name +"&JobTitle="+elementData.job_title+"&Date="+ elementData.entered_date; 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t  window.sessionStorage['Name'] = elementData.name; 
 
\t \t \t  window.sessionStorage['JobTitle'] = elementData.job_title; 
 
\t \t \t \t window.sessionStorage['Date'] = elementData.entered_date; 
 

 
**newOne.html** 
 

 
function LoadCandidateDetail() 
 
\t { 
 
\t document.getElementById('Name').innerHTML = window.sessionStorage['Name']; 
 
\t document.getElementById('JobTitle').innerHTML = window.sessionStorage["JobTitle"]; 
 
     document.getElementById('Date').innerHTML = window.sessionStorage["Date"]; 
 
\t } \t \t