lundi 30 mars 2020

How to have two separate functions not interfere with another?

I have an alert message that appears on the page for the first time creating a cookie on Dismiss. I created a function on page load to check if the cookie exists, do not display alert and if it does not exist display alert message. I also have another function in place to check if the pageTitle is "Test" display the alert message.

At the moment my alert message is showing even after clicking dismiss and a cookie is generated because of the second function check on pageTitle. If I remove the check on pageTitle I do get the desired result I want but the message appears on all pages when I only want it to appear with the pageTitle = Test

I am attempting to have both checks work properly with one another for example, if cookie exists do not show an alert, if it doesn't exist and the pageTitle = test show alert message

First function

  $(window).on("load", function (e) {
    $('.preloader').fadeOut('slow');

    if (document.cookie.includes("isDismissed=true")) {

        document.body.classList.add("alert.container");
    } else {
        document.body.classList.add("show-alert");
    }
});

Second function

 if("@pageTitle".indexOf("Test")  !== -1) {
       document.body.classList.add("show-alert");
    }

Aucun commentaire:

Enregistrer un commentaire