samedi 3 novembre 2018

Nooby javascript switch statement error - Please help! :)

I am trying to create a self-invoking function that will run once everytime the page loads.

The function will check what page(url/path) the user is on, then it will loop once through the switch statement and if any of the path names match it will then fire some info to an API.

I have an error in the code and know I nearly have the correct solution :/ Thank you in advance for any suggestions to achieve the above!

(function winLocation(path) {
return window.location.pathname.indexOf(path);
}
switch (true) {
case winLocation("stack"):
    console.log('This is a stack overflow page');
    // Fire info to api
    break;
case winLocation("google"):
    // Fire info to api if url has google in it
    break;
default:
    console.log("no urls/path names match");
}());

Aucun commentaire:

Enregistrer un commentaire