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 a function
Here is my code:
<script language="JavaScript">
var familyid = "id=8978566";
var corporateid = "id=8978565";
if(window.location.indexOf(familyid) === -1)
{
document.write("Family ID not found");
}
</script>
It would be awesome if i could get some guidance on this issue... I couldn't find similar issues using the .indexOf()
function
This is because indexOf was not supported in 3.3. 1/jquery. min. js so a simple fix to this is to change it to an old version 2.1.
The indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found. The indexOf() method is case sensitive.
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.
A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With