我目前有此代码来检查特定 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()
功能
window.location 是一个Location https://developer.mozilla.org/en-US/docs/Web/API/Location对象,而不是字符串,并且indexOf
is a String https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf (or Array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) 方法。
如果您想搜索查询参数,请尝试
window.location.search.indexOf(familyId)
或者如果你想检查整个网址,
window.location.toString().indexOf(familyId)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)