[Solved] Get url & change it on click


Pretty simple… Set up a click event handler on the button, get the location, adjust the string, set the URL.

// Get button reference
var btn = document.getElementById("btn");

// Set up click event handler
btn.addEventListener("click", function(){
  // Get current URL
  var url = window.location.href;

  console.log(url);

  // Change a portion of the string
  // Obviously, change the values to suit your needs.
  url = url.replace(".net", ".com");

  console.log(url);

  // Navigate to new URL
  window.location.href = url;

});
<button id="btn">Change URL</button>

0

solved Get url & change it on click