如果url符合特定条件,则重定向用户

时间:2019-05-26 02:06:18

标签: javascript string if-statement conditional-statements boolean-expression

如果URL包含某些条件,我希望将用户重定向到新网页。我似乎无法使OR条件正常工作。有什么想法吗?

if (
    document.location.href.indexOf("https://www.oct.ca/") > -1 &&
    document.location.href.indexOf("professionally_speaking") > -1 &&
    document.location.href.includes("2019-03" || "2018-12")
  ) {
    window.location = window.location.href.replace("https://www.oct.ca/", "http://professionallyspeaking.oct.ca/")

  }

1 个答案:

答案 0 :(得分:1)

您不能那样做-添加其他条件:

&& (document.location.href.includes("2019-03") || document.location.href.includes("2018-12"))
相关问题