.substring error: “is not a function”

后端 未结 4 1445
执笔经年
执笔经年 2020-12-30 19:34

I don\'t understand why I get an error message using the substring method to declare a variable.

I want to use the first part of the URL in a comparison.

Sit

4条回答
  •  忘掉有多难
    2020-12-30 20:01

    document.location is an object, not a string. It returns (by default) the full path, but it actually holds more info than that.

    Shortcut for solution: document.location.toString().substring(2,3);

    Or use document.location.href or window.location.href

提交回复
热议问题