Javascript 如果url符合某些条件,则重定向用户

Javascript 如果url符合某些条件,则重定向用户,javascript,string,if-statement,conditional-statements,boolean-expression,Javascript,String,If Statement,Conditional Statements,Boolean Expression,如果url包含某些条件,我希望将用户重定向到新网页。我似乎无法获得工作所需的条件。有什么想法吗 if ( document.location.href.indexOf("https://www.oct.ca/") > -1 && document.location.href.indexOf("professionally_speaking") > -1 && document.location.href.includes("20

如果url包含某些条件,我希望将用户重定向到新网页。我似乎无法获得工作所需的条件。有什么想法吗

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/")

  }

您不能这样做-添加另一个条件:

&& (document.location.href.includes("2019-03") || document.location.href.includes("2018-12"))

includes
方法不接受该布尔条件(该条件始终为真)。当您阅读它时,它听起来不错,但它没有JavaScript的意义。检查文档。你需要用括号括起来。实际上,如果URL是完全不需要的东西,比如
http://foo.bar/2018-12
。别担心@user3175043,随时乐意帮忙。如果我的答案解决了你的问题,请将其标记为已接受。