Chronological style switcher

I'm currently working on a JavaScript project to dynamically change the layout of my webpage at specific times of the day. I have also implemented functionality to revert back to the default style if any manual changes are made.

However, I've encountered an issue where upon clicking one of the buttons to manually change the style and then navigating to another page, the style is completely missing. Can anyone provide assistance with this problem?

Below is the code snippet:

// JavaScript Document
var mode = 0;

function webload() {
    if(mode == 0)
    {
        var d = new Date();
        var n = d.getHours();
        if (7 <= n && n < 18)
        {
            day();
        }
        else
        {
            night();
        }
    }
    elif(mode == 1)
    {
        day();
    }
    elif(mode == 2)
    {
        night();
    }
    elif(mode == 3)
    {
        highcon()
    }
}
function day() {
   document.body.style.background = 'url(images/day_bg_top.png) top scroll no-repeat, url(images/day_bg_bot.png) bottom scroll repeat-x, #53a3ff';
   document.getElementById('spacer').style.background = '#53a3ff';
   document.getElementById('spacer2').style.background = '#53a3ff';
   mode = 1
}
function night() {
   document.body.style.background = 'url(images/night_bg_top.png) top scroll no-repeat, url(images/night_bg_bot.png) bottom scroll repeat-x, #000c36';
   document.getElementById('spacer').style.background = '#000c36';
   document.getElementById('spacer2').style.background = '#000c36';
   mode = 2
}
function highcon() {
    document.body.style.background = 'url(images/night_bg_top.png) top scroll no-repeat, url(images/night_bg_bot.png) bottom scroll repeat-x, #000c36';
    document.getElementById('spacer').style.background = '#000c36';
    document.getElementById('spacer2').style.background = '#000c36';
    mode = 3
}

Answer №1

How does the following page determine the appropriate style? It is important to store the user's preference, like in a cookie, while also updating the current page with the chosen style. This way, when the user navigates to the next page, it can automatically apply the desired style based on the information stored in the cookie.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to extract multiple values from an input field using jQuery?

Looking to retrieve input field values that are within a foreach loop using jQuery? Below is the HTML structure: @foreach ($products as $product) <div class = "form-row"> <input type="text" name="quantity" ...

Three Divisions Positioned at the Top, Middle, and Bottom

I need to place 3 divs at the top, middle, and bottom positions. To achieve this, I have used jQuery to calculate the viewport height and apply a percentage of it to the top and bottom divs. However, resizing the page causes issues as the middle div overl ...

Is there a way to assess the height of a container and adjust the CSS accordingly?

Imagine you have a container that fills 100% of the page with a footer positioned at the bottom left within that container. The footer is set to be at left:0px and bottom:0px. Using JQuery, is it possible to detect the height of the container and, if it f ...

Display an image overlaying a div

I am attempting to position an image outside of its parent div in such a way that it appears to be sitting on top of the div without affecting the height of the parent. However, no matter what I attempt, the image consistently gets clipped by the parent di ...

Do not include hidden div with display:none in nth child calculation

My website includes a List Group created with Bootstrap 4 HTML <ul class="list-group"> <li class="list-group-item">Cras justo odio</li> <li class="list-group-item">Dapibus ac facilisis in</li> ...

acquiring JSON information from different domains

I am in need of creating an ajax request to fetch JSON data from a RESTful Web Service that is hosted on a different domain (KARAF using cxf). The client making the ajax call is situated on a separate domain (Apache Tomcat). The Web Service responds with ...

Distinguishing Between Angular and Ajax When Making Requests to a NodeJS Server

Trying to establish communication between an Angular client and a NodeJS server. Previous method using JQuery $.ajax({ url: "/list", type: "POST", contentType: "application/json", dataType: "json", success: function(data) { console.log("Data ...

Get the current executing event in jQuery by detecting multiple jQuery events

When I have a series of jQuery events like this: $(selector).on('click keydown blur', function(){ //do something } Is there a way to determine which event triggered the function at the current time? For instance, consider the following sce ...

React Array Not Behaving Properly When Checkbox Unchecked and Item Removed

When using my React Table, I encountered an issue with checkboxes. Each time I check a box, I aim to add the corresponding Id to an empty array and remove it when unchecked. However, the current implementation is not functioning as expected. On the first c ...

Having trouble incorporating an API module into a nested component in Vue

I have encountered a perplexing issue when attempting to import an API module into a nested component within a Vue application. After simplifying the problem as much as possible, I created a codesandbox example to demonstrate it. The problem arises when ...

The issue of slides overlapping in a Javascript slideshow during auto play mode

I encountered an issue while creating an automatic slideshow with 4 slides. Upon autoplay for the first time, slide 1 overlaps slide 4, as well as slide 2 and 3. This only happens once after the site loads. However, on subsequent playthroughs or when using ...

Challenges with creating a responsive layout for a Bootstrap timeline

I've been utilizing a Bootstrap-based sample timeline, and while it's functional overall, some layout elements become misaligned when resizing the window. I've made adjustments to the code so that all timeline items are positioned to the rig ...

NodeJS/WebdriverJS: Error - 'Element is not connected to the webpage'

Hello there! I am new to WebDriver (chromedriver) and my knowledge of JavaScript syntax is quite basic, so please excuse me if my code appears messy. Currently, I have a clickAllElements(); function that identifies all elements within a class and performs ...

Struggling to integrate data retrieved from a Vue.js API

Once I receive the API call with an attached string input, I successfully get the result. However, I am struggling to incorporate it into my frontend. I have attempted various solutions found online without success and cannot seem to grasp the concept. Her ...

Parsing JSON data in JavaScript

I am facing an issue with parsing JSON using JavaScript. After the completion of the loop, my variable 'text' is not getting the expected result. Can someone please explain how I can correctly parse this JSON? var xmlr = null; var text = '& ...

The content of one div is encroaching on another div's space

I'm having trouble with my div text overlapping in unexpected ways. The source of the text is a JS file, so it may not appear correctly here. The text in the div.subheader class keeps overlapping into the div.resource class, which is causing layout i ...

An in-depth guide on implementing Highcharts.Tooltip functionality in a TypeScript environment

Currently, I am trying to implement a tooltip activation on click event in Highcharts by following an example from this URL: Highcharts - Show tooltip on points click instead mouseover. The challenge I'm facing is that I am using TypeScript and strugg ...

What is the best way to insert a vertical line divider between two tabs?

Looking to add a vertical line (|) between the tabs. <p-tabView> <p-tabPanel header="Header I"> <p> Lorem ipsum dolor sit amet... </p> </p-tabPanel> <p-tabPanel header=" ...

Is 'not set' in Google Analytics indicating the browser version?

I came across a similar question on Stack Overflow, but my situation is unique. After adding the Google Analytics script to my project (Angular4), I noticed that I am receiving all information except for browser information. Some browsers are showing &apo ...

Is there a way to replace a text box with a <label>, <div>, or <span> using jQuery?

Currently, I am working on "single sourcing" a form page that can switch between edit mode and view mode. Rather than utilizing the ASP.Net FormView or DetailsView controls, I am exploring alternative methods. One of the challenges I encountered is that t ...