Can I remove parameter from URL generated by video playlist in Elementor

Viewed 325
2 Answers

This should do the trick.

const url = 'http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967'
url.replace(url.split('/')[6], '')
  1. split, well.. splits the string into an array by the / character.

  2. At index 6 the array contains the ?playlist=f68425e&video=b8a9967 substring which can than be removed (i.e. replaced by the empty string) using replace.

A more general approach to removing the last part of the url might be to use the array length instead of specifying the index:

const url = 'http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967'
const urlArr = url.split('/')
url.replace(urlArr[urlArr.length - 1], '')

Update:

Another way to do this is using the URL API

const url = new URL('http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967');
const result = url.origin + url.pathname

or in a function:

const removeParameter = u => {
  const url = new URL(u);
  return url.origin + url.pathname
}

You might have to check the specification for further details (browser support etc)

My brother help me with the next script. Put a "HTML Elementor Widget" with the following:

    <script>
function getURLParameter(name) {
  return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);
}

function hideURLParams() {
  //Parameters to hide (ie ?playlist=value, ?video=value, etc)
  var hide = ['playlist','video'];
  for(var h in hide) {
    if(getURLParameter(h)) {
      history.replaceState(null, document.getElementsByTagName("title")[0].innerHTML, window.location.pathname);
    }
  }
}

window.onload = hideURLParams;
</script>
Related