document.location.indexOf不是一个函数

use*_*849 2 javascript jquery indexof typeerror

我在我的特定网站上使用应用程序HotJar.现在这个应用程序记录会话(鼠标移动和一切的完整录制).可以选择"自动标记"录音,以便通过搜索特定标签在我的库中找到一些录音.

我写了一个小脚本,应该标记来自特定来源的访问.它看起来像这样:

<script>
$(document).ready(function() {
    if (document.location.indexOf('?utm_source=Bing')  > -1 ) {
        hj('tagRecording', ['Bing_source']);
    }
    if (document.location.indexOf('?gclid=') > -1 ) {
        hj('tagRecording', ['AdWords_source']);
    }
    if (document.location.indexOf('?utm_source=YouTube') > -1 ) {
        hj('tagRecording', ['YouTube_source']);
    }
    if (document.location.indexOf('?u=') > -1 ) {
        hj('tagRecordings', ['Mailchimp_source'])
    }
});
</script>
Run Code Online (Sandbox Code Playgroud)

问题是,我收到以下错误:

Uncaught TypeError: document.location.indexOf is not a function
Run Code Online (Sandbox Code Playgroud)

我可能会遗忘一些东西但是当在stackoverflow上搜索时,这个函数变成了一个工作函数.

有没有人有想法?

Que*_*tin 6

indexOf是一种在字符串上找到的方法.location不是一个字符串.

location.toString()是一个字符串,location.href是一个字符串.

你可能想要查看,location.query因为你只是在玩查询字符串.