Tips for managing the background color of a box when the function is constantly refreshing in Internet Explorer

function process(Objects) {            
         var objectId = Objects;                
         displayContent(objectId);             

     }

function displayContent(objectId) {
        var boxId = objectId.id;
        var color = retrieveColor(objectId.status); // Different colors are retrieved from the database for each refresh
        if($('#boxcontent'+boxId).is(':visible')) {
        } else {
            var boxText = document.createElement("div");
            boxText.id='boxcontent'+boxId;
            boxText.style.cssText = "white-space:nowrap;text-align:center;border:2px solid ;background-color:"+color+";opacity:0.9;filter:alpha(opacity=90);-moz-border-radius: 5px;border-radius: 5px;color:black !important;";
            return boxText;
        }
        $('#boxcontent'+boxId).css({'background-color':color});

     }
  • This content box is displayed on a map.
  • The background color of this box does not appear correctly in IE, but works fine in FireFox.
  • The first function refreshes every 10 seconds with different objects (each refresh changes the color).
  • In IE, the color is not changing properly - seeking help to solve this issue.

Answer №1

  • Make sure it refreshes every 10 seconds.
  • You mentioned that different objects will be received every 10 seconds.
  • Internet Explorer may encounter issues with resending data while refreshing, such as caching problems.

var color = getBackgroundColor(imgid.status);//I am passing different colors for each refresh (e.g. #D03C78 or #B8B8B8) values from the Database 
alert(imgid.id+" : color is : "+color)

  • Let's test this in Firefox and IE.

Answer №2

It's quite puzzling why IE isn't applying the color based on the provided information... It could be a CSS issue or a lack of commas, among other possibilities. Nevertheless, let me try to assist you. This code snippet seems to have a mix of JavaScript and jQuery, so I've attempted to consolidate it into jQuery for better compatibility with different browsers, especially IE. Additionally, I've introduced a class for cleaner organization.

// Initialization
var Objs = {
    id : 'test',
    status : "red"
};
// Calling function
first(Objs);

function first(Objs) {            
    var imgid= Objs;                
    secondMethod(imgid);             
}

function secondMethod(imgid) {
    var boxid = imgid.id;
    var color = imgid.status;

    if($('#boxcontent' + boxid).length < 1) { // If box doesn't exist, create new one
        var boxText = $("<div></div>")
            .attr("id", "boxcontent"+boxid)
            .addClass("basicStyleNoColor")
            .css({
                'background-color' : color,
                opacity : 0.9 // Jquery sets filter for IE...
            });

        $("body").append(boxText); // Insert here or return and insert later
        return boxText;
    }
}

CSS:

.basicStyleNoColor {
    white-space:nowrap;
    text-align:center;
    border:2px solid ;
    -moz-border-radius: 5px;
    border-radius: 5px;
    color:black !important;    
}

You can find the code on Fiddle.net

I hope this explanation proves helpful in some way...

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

Move router parameters to separate files to streamline and organize code

I have encountered a bit of an issue. I currently have the following code in my routing.js file where I define both my parameter and route. I have moved the routes to a separate router instance in my routing.js file, but I am struggling to separate the par ...

Using <span> tags to wrap sentences within <p> tags while maintaining the rest of the HTML formatting

In order to achieve my goal, I have utilized the following code to extract content within tags and encapsulate each sentence in tags for easier interaction. $('p').each(function() { var sentences = $(this) .text() ...

Hovering over a dropdown menu results in the color not completely filling the background of the desired element

.nav-main { background-color:#09F; width:100%; height:100px; color:#FFF; line-height:40px; } .nav-main .logo{ float:left; padding: 40px 5px; font-size:1.4em; line-height: 20px; } .nav-main > ul { margin:0; ...

Error: JSON key data not present in rendering

Here is a JSON string I am working with: {"{\"nodeName\":\"abc\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]," {\"nodeName\":\"pqr\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]} ...

The route parameters seem to be malfunctioning when using the Google Maps Directions API

Currently, I am attempting to transfer the latitude and longitude of a location from one HTML file to another using the $routeParams feature. In the second HTML file, I utilized the Google Maps directions API to display the directions from the source lati ...

Can you explain the process of a put request in Angular, Express, and Mongoose?

My colleague and I are currently deciphering the inner workings of a code snippet generated by a tutorial. Our main focus is on how the client/server communication flows once line 8 of factory.js is triggered: factory.js app.factory('postFactory&apo ...

jquery logic for iterating through all elements in a select menu encountering issues

In search of a solution to iterate through all options in a dropdown list using code, comparing each to a variable. When a match is found, I aim to set that particular value as the selected item in the dropdown and then exit the loop. Here's what I&ap ...

The AngularJS $HTTP loop counter fails to update

When working with an HTTP service and binding JSON data to HTML, I implemented the following code: This function uses a 2-second timer to automatically fetch data whenever there is a change in the backend. function sampleDevices ...

Creating a personalized context menu in Javascript: The ultimate guide to incorporating copy and paste features

We are developing a unique context menu for our online text editor, complete with copy/paste options. However, we encountered difficulties accessing the system clipboard from within the browser. It once seemed impossible to achieve this, as discussed in th ...

Is it possible to retrieve the createdAt timestamp without displaying the 'GMT+0000 (Coordinated Universal Time)'?

After conducting an extensive search, I have yet to find a satisfactory answer. My goal is to configure it without including the CUT time. {name: "Registered:", value: `${user.createdAt}`}, {name: "Joined:", value: `${message.guild.joinedAt}`} Presently, ...

The input tag contains an empty Request.Form

My issue lies in using Request.Form to retrieve text from an input field, as the value always ends up being empty. My goal is to extract the text value from the input tag and use it to query my database. I have attempted to write to an ASP TextBox but enco ...

jQuery dialog box - Create customized dialog boxes with ease

I am facing an issue with my dialog code // function to display dialog for user signup function new_user_signup() { $.get("/actions/_new_user_account.php", function(data){ $("#dialog").html(data); }); $("#dialog").dialog({ width: 4 ...

Guide on applying CSS to option tag within a select element in VUE.js

I am attempting to design a dropdown menu that resembles the one shown in the image. However, I'm currently unable to include any CSS styling. Can anyone provide guidance on how to create a customizable select dropdown in Vue? https://i.stack.imgur.c ...

Admin-on-rest sidebar navigation menu

Hello everyone! I am new to ReactJS and admin-on-rest. I am currently studying from this documentation and I am interested in creating a navigation submenu similar to the one shown here. I have tried searching on Google but haven't found what I need. ...

Guidelines for accessing the Coinbase exchange API from a localhost

Following the instructions in the Coinbase Cloud documentation, I tried running this code on the client side using JavaScript: const options = { method: 'GET', headers: { Accept: 'application/json', 'cb-access-key&ap ...

How can I retrieve the name of an HTTP status code using JavaScript and AngularJS?

My web application is built using AngularJS, JS, JQ, HTML5, and CSS3. It interacts with our projects' REST API by sending various HTTP methods and manipulating the data received. The functionality is similar to what can be achieved with DHC by Restlet ...

Getting JSON data from jQuery in Asp.Net

After creating a JSON object in jQuery with the following structure: { "objects":[ { "ObjectId":1, "Line1":"Software", "Line2":"Microsoft", "Line3":"Web", "Line4":"Asp.Net", "Line5":"jQu ...

How to set up 'ng serve' command in Angular to automatically open a private browsing window?

I am looking for a way to open my project in an Incognito Mode browser without storing any cache. Is there a specific Angular CLI flag that can be included in the ng serve -o command or in the Angular CLI configuration file to enable opening a browser in ...

No content appears on the multi-form component in React

After several attempts at building a multi-step form in React, I initially created a convoluted version using React.Component with numerous condition tests to determine which form to display. Unsatisfied with this approach, I decided to refactor the code f ...

What are some ways to adjust the page being served in node.js?

I have set up my server.js file with necessary dependencies and routing for handling POST requests. However, I am looking to dynamically update the webpage served by this server when a POST request is received on /message endpoint. These requests are trigg ...