2017-09-02 126 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>

我希望这有助于。