jquery based on a condition

359 Views Asked by At

I am working on a survey platform. By default I have a footer that shows up in all survey pages. I need the footer to display only on the first display page. In order to do this I am attaching this jQuery to all pages where I want the footer hidden:

jQuery("#Footer").hide();

The issue I am having now is that based on a link condition, the first page of the survey can be page1 or page2. This means. I have 2 scenarios:

  1. I access the survey using link1. This should start on pag1, pag2, pag3. The footer is displayed only on pag1 and is hidden by jQuery on the subsequent pages.
  2. I access the survey using link2. This should start display pag2 first. The footer is not displayed and is hidden by the jQuery I applied.

Any ideas?

3

There are 3 best solutions below

0
On BEST ANSWER

Add this script to pag1 and pag2.
I assume your URL to be something like : link1/**/**/pag1 or link2/**/**/pag2

var pageURL = window.location.href;

if((pageURL.includes("link1") && pageURL.includes("pag1")) || 
   (pageURL.includes("link2") && pageURL.includes("pag2")))
{
    jQuery("#Footer").show();
}
else
{
    jQuery("#Footer").hide();
}
0
On

Thank you all for your support. The JS code is ok and works. The problem was where the code was being included within the platform. I know learn that code gets executed differently depending on the ref. it is included in. This was an internal issue. Nothing specific to the code.

0
On

Approach 1

You can show/hide footer based on URL, specifically the page name

Approach 2

you can add a query string parameter and add different values based on adapted route to Page2, then based on query string parameter values you can make decision to show/hide footer.