Internet Explorer has trouble running remote JavaScript correctly, but it works perfectly fine when running locally

For some reason, my webpage functions perfectly in all browsers except for IE 10. Oddly enough, when I test the page locally on IE 10, there are no issues whatsoever; the problems only arise when accessing the page remotely using IE 10.

The JavaScript code is meant to calculate the dimensions of the main text div and adjust the height and width of the off-screen divs accordingly. However, IE 10 seems to mishandle this calculation. It is crucial to set the width of these off-screen divs to ensure they animate correctly when an item from the menu is clicked.

I carefully inspected the code for any deprecated functions but found none. The syntax appears to be correct as far as I can tell. Surprisingly, the console in IE does not show any error messages.

Can anyone shed light on why the page works flawlessly across all browsers locally, yet only displays incorrectly on IE when accessed remotely?

EDIT:

I tried removing the function brackets at initialization so that the DOM could initialize properly, but unfortunately, this did not resolve the issue.

Here's the script embedded in the head section of the page:

<script src="scripts/jquery-1.10.1.min.js"></script>
<script>
var mainTextDiv = null;
var animate;
var acc = 0;
var currentTab = "home";
var nextTab;
var working = 0;
var bar = 600;
var divW;

function init(){
    onWC(currentTab);
    document.getElementById(currentTab).style.width = 'auto';
    divW = document.getElementById(currentTab).offsetWidth;
    document.getElementById("home").style.width = divW + "px";
    document.getElementById("profile").style.width = divW + "px";
    document.getElementById("news").style.width = divW + "px";
    document.getElementById("forums").style.width = divW + "px";
    document.getElementById("webshop").style.width = divW + "px";
    document.getElementById("status").style.width = divW + "px";
}

function onWC(tab){
    var divh = document.getElementById(tab).offsetHeight;
    document.getElementById('tabcontainer').style.height = ( divh + 50 ) + "px";
}
function moveDiv(tabName){
    if (currentTab == tabName){
        return;
    }
    if (working == 1){
        return;
    }
    working = 1;
    nextTab = tabName;
    removeDiv();
}
function removeDiv(){
    mainTextDiv = document.getElementById(currentTab);
    mainTextDiv.style.left = parseInt(mainTextDiv.style.left) + (0.5+acc) + "px";
    if (parseInt(mainTextDiv.style.left) > 2000){
        mainTextDiv.style.left = 2000 + "px";
        onWC(nextTab);
        getDiv();
        return;
    }

    acc += 0.15;

    animate = setTimeout(removeDiv,10);
}
function getDiv(){
    mainTextDiv = document.getElementById(nextTab);
    mainTextDiv.style.left = parseInt(mainTextDiv.style.left) - (0.5+acc) + "px";   
    if (parseInt(mainTextDiv.style.left) <= 0){
        mainTextDiv.style.left = 0 + "px";
        currentTab = nextTab;
        working = 0;
        return;
    }

    acc -= 0.15;

    animate = setTimeout(getDiv,15);
}
window.onload = init;
window.onresize = init;

$(function() {
    $("#menu ul li a").hover(
        function(){
            $(this).css("background-color", "#525252");
            $(this).css("color", "#FFF");
        },
        function() {
            $(this).css("background-color", "#FFF");
            $(this).css("color", "#525252");
        }
    );
});
</script>

Answer №1

Replace window.onresize = init(); with window.onresize = init;

Currently, the init() function is being called immediately upon loading the JS file, causing an error due to the DOM not being fully loaded.

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

The ordering of parameters should not impact the functionality of Typescript generics, though currently it does

My mergeArrays generic function is designed to not rely on the order of parameters. However, when it is used within another generic function, the result seems to depend on the order. This unexpected behavior is puzzling. type Fn = (...args: any[]) => an ...

Styling fonts by using CSS transitions

Here's a challenging query to ponder: Can CSS transition with fonts successfully incorporate changes in font-weight and font-family? Take a look at this example: This question delves into the realm of Donald Knuth's MetaFont, likely to bring ...

Troubleshooting the malfunctioning Bootstrap Dropdown Navbar in Rails 6

I am currently integrating Bootstrap with a Rails 6 application. I utilized yarn to install jquery and popper.js. Despite including a dropdown in my navbar, it fails to open and instead just redirects me to the current link with an added #, which serves no ...

Adjust the spacing between the title and other elements in an R Shiny application

How do I modify the font and size of a title, as well as add some spacing between the title and other elements? navbar <- navbarPage( Title = "Intervals", tabPanel("Data Import", sidebarLayout(sidebarPanel(fi ...

Exploring the World of Audio Playback with R Shiny

For this question, I am incorporating the following libraries: library("shiny") library("tuneR") library("markdown") Although, it seems that only shiny is relevant in this context. According to the Shiny tag glossary, I should be able to utilize tags$a ...

Increase the font size of the text inside a table cell without altering the cell's width

Let me clarify my query with some images. This is how my current setup looks: https://i.sstatic.net/tyelv.png Everything is contained within a table, where the boxes span the width of the table. However, I need the data field to expand across the full sc ...

Incorporate a CSS class name with a TypeScript property in Angular version 7

Struggling with something seemingly simple... All I need is for my span tag to take on a class called "store" from a variable in my .ts file: <span [ngClass]="{'flag-icon': true, 'my_property_in_TS': true}"></span> I&apos ...

Navigating Angular's Credit Card Input Functionality

I am looking to limit the input capacity to 16 numbers and add a space between each set of 4 numbers. After conducting an extensive search for a credit card input that allows users to enter 16 digits with a " - " or space in between, all results were for ...

Initiating an AJAX request to communicate with a Node.js server

Recently, I started exploring NodeJS and decided to utilize the npm spotcrime package for retrieving crime data based on user input location through an ajax call triggered by a button click. The npm documentation provides the following code snippet for usi ...

After resizing the window in jQuery, the scroll to section functionality does not behave as anticipated

My scroll function is not working properly after window resize. Here's how I want it to work: I resize the window. After resizing, when I click a specific menu item, the window should scroll to the section corresponding to that item with an offs ...

How to toggle the visibility of a search bar in ReactJS?

I am trying to implement a simple search bar in reactjs without a dedicated close button. I want the same button to toggle between opening and closing the search bar. Below is the code snippet I have experimented with, but unfortunately, it's not fun ...

Generating a personalized list of objects from JSON information

My json objects array contains the following data: [{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":10},{"SensorID":2,"Temperature":34.0,"Humidity":43.0,"Carbon":87.0,"DateTime":"2017-03-09T12:00:00","I ...

Issue with material table not showing data

Problem I've been working on integrating a material design table into my project, but I'm running into an issue where the data isn't showing up. I followed the example provided here but all I see is a single vertical line on the page: https ...

Arranging H1 Styling with CSS for Optimum Alignment

My issue revolves around a DIV tag adorned with a background image: <a href="#"> <div class="pagebar jquery"> <h1>JQuery Demonstrations</h1> </div> </a> The CSS applied to this element is as follows: .pagebar ...

The sluggish rendering speed of AngularJS is causing a delay in displaying the loader

Within my application, I have tabs that load a form in each tab with varying numbers of controls. Some tabs may contain a large number of controls while others may have fewer. My goal is to display a loader while the contents are being rendered into the HT ...

Determining the character encoding of a JavaScript source code file

For my German users, I want to display a status message with umlauts (ä/ü/ö) directly in the source file instead of requiring an extra download for messages. However, I'm having trouble defining the encoding for a JS source file. Is there a way si ...

Whenever trying to access data from the database using DataTable row(), it consistently remains undefined and fails to retrieve any information

While working on my application, I attempted to display all the data in a DataTable from the database. Unfortunately, instead of achieving this, I encountered an error from the server. Upon receiving the error, the dataTable object was displayed as follows ...

ReactJS Component Alignment Guide

I am currently learning React and facing difficulty in aligning a component to a specific position. import React from "react"; import "./styles.css"; import { Typography, Container, Grid, Button } from "@material-ui/core"; imp ...

Integrate Angular 2 into the current layout of Express framework

After generating an express structure with express-generator, I ended up with the standard setup: bin bld node_modules public routes views app.js package.json Now, I want to enhance the views and routes directories by organizing them as follows: v ...

Using ASP.Net MVC, it is crucial to send additional data along with a Partial View

I'm looking to send additional data, enclosed in a JSON object, along with a Partial view to the client. There are two possible methods that come to mind: Send the JSON object and then make a separate call to load the contents of the partial view in ...