Uncaught TypeError: Undefined is not a function on indexOf

后端 未结 1 1027
再見小時候
再見小時候 2021-02-07 08:31

I currently have this code to check the website URL GET options for a specific ID, but whenever this code is run, I get a weird error: Uncaught TypeError: Undefined is not

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 08:52

    window.location is a Location object, not a string, and indexOf is a String (or Array) method.

    If you want to search the query params, try

    window.location.search.indexOf(familyId)
    

    or if you want check the whole url,

    window.location.toString().indexOf(familyId)
    

    0 讨论(0)
提交回复
热议问题