16

我目前有这段代码来检查特定 ID 的网站 URL GET 选项,但是每当运行这段代码时,我都会收到一个奇怪的错误:Uncaught TypeError: Undefined is not a function

这是我的代码:

<script language="JavaScript">
    var familyid = "id=8978566";
    var corporateid = "id=8978565";

    if(window.location.indexOf(familyid) === -1)
       {
        document.write("Family ID not found");
       }

</script>

如果我能在这个问题上获得一些指导,那就太棒了......我无法使用该.indexOf()功能找到类似的问题

4

1 回答 1

21

window.location 是一个Location对象,而不是字符串,并且indexOf是一个String(或Array)方法。

如果要搜索查询参数,请尝试

window.location.search.indexOf(familyId)

或者如果你想检查整个网址,

window.location.toString().indexOf(familyId)
于 2014-06-28T21:45:42.753 回答