我可以从 Elementor 中的视频播放列表生成的 URL 中删除参数吗

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

Elementor Pro 有一个新的小部件,视频播放列表。它将参数附加到 URL,如下所示:http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967

这对于 SEO 和 UX 来说显然很糟糕。有没有办法删除 ?playlist=f68425e&video=b8a9967 ?

这应该可以解决问题。

const url = 'http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967'
url.replace(url.split('/')[6], '')
  1. split,嗯..通过 / 将字符串拆分为数组 字符.

  2. 在索引 6 处,数组包含 ?playlist=f68425e&video=b8a9967 子字符串,然后可以使用 replace.[=20 将其删除(即替换为空字符串) =]

删除 url 最后一部分的更通用方法可能 是使用数组长度而不是指定索引:

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

更新:

另一种方法是使用 URL API

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

或函数中:

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

您可能需要查看规范以获取更多详细信息(浏览器支持等)

弟弟帮我写下一个剧本。 放置一个“HTML Elementor Widget”,其中包含以下内容:

    <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>