首页 > 解决方案 > 如果单词以开头,则替换 url

问题描述

如果单词以getlink开头,我想替换 url 。

  download file: xxxxxxxxxx.com 

  getlink file:  xxxxxxxxxx.com

仅将 xxxxxxxxxx.com 替换为 mmmmmmmm111.com

我怎样才能使用 JavaScript 做到这一点?

标签: javascriptjqueryhtmlregexreplace

解决方案


只需使用 window.location.href 即可获取当前页面的 url。

在您的 javascript 代码中只有一些看起来像这样的代码

if (window.location.href == "xxxxxxx.com") {
   location = "mmmmmmmmmm111.com"
}

如果您可以更具体并包含一些更详细的解释和代码,那将是一个帮助。


推荐阅读