2017-09-02 122 views
0

我確實花了2個多小時試圖找到一個簡單的答案,這可惜我不能。URL份額傳遞參數

問題的方案:

  1. 用戶瀏覽到ulan.be,選擇3個參數並繼續。

  2. 頁面重定向他像here

  3. 的用戶希望通過社交分享按鈕的其他用戶共享此(比如電子郵件或WhatsApp的),但URL被削減和參數沒有得到通過。

基本上我需要的是一個WordPress插件或基本JS代碼以使在2 第二用戶「的地址欄複製粘貼」。

任何幫助表示讚賞 - 謝謝你。

+0

什麼是執行上面的函數的代碼? – Sheedo

+0

它是一個名爲ezfc form calculator的第三方插件。它使用這些參數將字段值轉發到下一頁,我希望第二個用戶使用相同的參數瀏覽同一頁面。 –

+0

某些格式問題+次要語義 – meowgoesthedog

回答

0

這是我將如何處理這一簡單的邏輯:

var sel = document.querySelector("#ddlViewBy"); 
 
var input = document.querySelector("input#location"); 
 
var button = document.querySelector("button"); 
 
var param1 = ''; 
 
var param2 = ''; 
 

 
button.addEventListener("click", function(evt){ 
 
    param1 = sel.options[sel.selectedIndex].value; 
 
    param2 = input.value; 
 
    //Just to check the value 
 
    //alert(param1 + ", " + param2); 
 
}); 
 

 
//Then reconstruct your URL bar with the params above 
 
/** 
 
    * orig_url = window.location.href; 
 
    * window.location.href = orig_url + '?city=' + param1 + '&zip=' + param2 
 
    * 
 
**/
<select id="ddlViewBy"> 
 
    <option value="1">test1</option> 
 
    <option value="2" selected="selected">test2</option> 
 
    <option value="3">test3</option> 
 
</select> 
 

 
<input type="text" id="location" placeholder="Location" /> 
 

 
<button type="button">Submit</button>

我希望這有助於。