简体   繁体   中英

URL share passing parameters

I did spend more than 2 hours trying to find an easy answer to this but unfortunately I could not.

The scenario of the problem:

  1. A user browses to ulan.be , selects 3 parameters and continues.

  2. The page redirects him to something like here .

  3. The user wants to share this with another user via a social share button (say email or Whatsapp) but the URL gets cut and parameters don't get passed.

Basically what I need is a Wordpress plugin or a basic JS code to enable a "copy paste of the address bar" to the 2 nd user.

Any help is appreciated - thank you.

Here's how I would approach this simple logic:

 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> 

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM