Problem with JavaScript in Internet Explorer 8

To ensure a consistent bottom background at all times on the page, I devised a method to determine whether or not the bottom part needed to be pushed down based on the window height and main content height. However, I encountered an issue when the content block was too short relative to the larger computer screen, resulting in the bottom background being right at the end of the content with a gap until the bottom of the screen. To rectify this, I decided to increase the height of the content so that it adequately fills the space at the bottom, eliminating the gap.

Below is the JavaScript solution I implemented:

window.onload=function(){
    var winHeight = window.innerHeight;
    var fixIt = winHeight - 200;
    var divHeight = document.getElementById('bottomDiv').clientHeight;
    alert(winHeight - divHeight);
    if (divHeight < winHeight) {
        var fire = document.getElementById('innerDiv').style.height = fixIt + "px";
    }
};

Unfortunately, this script works effectively across browsers except for IE7-IE8. I am seeking assistance in finding a solution for these older IE browsers.

Thank you, Art

Answer №1

window.onload=function(){
    //                                 ^---------------------------------------^
    var windowHeight = window.innerHeight || document.documentElement.clientHeight;
    var adjustHeight = windowHeight - 200;
    var containerHeight = document.getElementById('bottomDiv').clientHeight;
    alert(windowHeight - containerHeight);
    if (containerHeight < windowHeight) {
        var resizeElement = document.getElementById('innerDiv').style.height = adjustHeight + "px";
    }
};

Answer №2

Perhaps you could consider applying your "bottom" background to the html element first, and then layering it with a different background (maybe within your div#content) in the upper area.

Alternatively, innerHeight may not be compatible with IE8.

Check out this alternative for window.innerHeight in IE8

Give this a try:

var winHeight = document.documentElement.clientHeight

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

Update the icon within the expandable display

Is there a way to change the plus sign to a minus sign in an expandable table view on click? (changing fa fa-plus to fa fa-minus) The goal is to have the plus sign displayed when the view is compressed and the minus sign displayed when it is expanded. If ...

Exploring the functionality of Kendo Grid within an Angular application

Currently, I am facing some challenges while trying to execute my Karma tests using the kendo grid within a fresh Angular project. The specifications for this specific component are outlined below: import { async, ComponentFixture, TestBed } from '@a ...

Understanding how to utilize jQuery or prototype to interpret onclick event containing "setLocation(...)" can enhance the functionality

I am dealing with a specific tag: <button onclick="setLocation('http://mysite.com/checkout/cart/add/product/17/')" /> My goal is to trigger an ajax request when the button is clicked. I want to extract the URL segment "product/17" and app ...

Initiate a series of tasks and await their completion using RxJS / Redux Observables

My app requires an initialisation action to be fired, followed by a series of other actions before triggering another action. I found a similar question on Stack Overflow However, when attempting this approach, only the initial APP_INIT action is executed ...

A guide on showcasing items on an html webpage through the use of javascript

Currently, I have a series of hardcoded HTML elements in my code snippet. <!-- Reciever Message--> <div class="media w-50 ml-auto mb-3"> <div class="media-body"> ...

Working with Javascript objects and arrays

Need assistance with manipulating/updating a JavaScript array. Hoping for some help. The initial array looks like this: array('saved_designs'=array()); In Javascript JSON format: {"saved_design":{}} I plan on adding a label and its associa ...

The only thing visible on my project is the homepage, void of any buttons or additional pages

After completing this school project, I believed that everything was done correctly. However, as I faced issues with the code, I decided to seek help and share my app.js and bin section for clarification. Starting it with npm on the localhost as shown in ...

Ways to extract dropdown selection into a .php script

I am trying to capture the selected dropdown value in my .php file, which is used for sending emails. When a user selects one of the 6 options from the dropdown menu, I want that selected option to be included as the email subject. Below is the HTML code ...

What is the reason this switch statement functions only with one case?

Why is the switch statement not functioning properly? It seems to correctly identify the values and match them with the appropriate case, but it only works when there is a single case remaining. If there are multiple cases to choose from, nothing happens. ...

extract all elements from an array nested within another array

I am having difficulty extracting data from an array file in PHP. I was able to read it and convert it into a PHP array, but now I want to display the stored information in a table, however, I keep getting incorrect values. How can I retrieve the informat ...

Using Angular and nativeElement.style: how to alter cursor appearance when clicked and pressed (down state)

I am working with a native elementRef CODE: this.eleRef.nativeElement.style = "_____?????_____" What should go in "???" in order to apply the :active style to the element? (I want to change the cursor style when the mouse is clicked down, not when it is ...

How can I change the text of a single button by clicking on it without affecting the other buttons that share the same

Currently, I am implementing a posting system where posts can be added using a button. The posts have two additional buttons - one to show/hide content and the other to delete content. I am utilizing jQuery's slideToggle event to toggle the visibility ...

The findIndex method is failing to retrieve the accurate index

The index returned by findeIndex in an express router function is incorrect. module.exports.nearestOffices = (req, res, next) => { Order.findById(req.params.idOrder).exec() .then(order => { return Promise.all([ Promise.resolve(or ...

What is the process for updating the internal TypeScript version in VS Code?

When using VS Code, I noticed it comes with its own TypeScript version: Is there a way to update this? The current version is 4.9.3. https://i.sstatic.net/vEx85.png ...

Ensure that clicking on an element closes any currently visible elements before opening a new element

Take a look at my code snippet below. I am working on creating multiple clickable divs that reveal different content when clicked. However, the issue I am facing is that currently, both content blocks can be displayed simultaneously. My goal is to have onl ...

Insert image using AJAX

I am attempting to use Ajax to dynamically add an <img> element to a div on my webpage. The image's name needs to be fetched from a database. Although I have successfully added the <img> tag to the div and set the correct source (src) att ...

When the drop-down selection changes in AngularJS, the textbox value becomes empty

When the user selects "text-box-value-empty", the textbox should be disabled and cleared. I have attempted to accomplish this using the code below, but unfortunately, it is not working as expected. If the user enters a value and then selects "text-box-valu ...

Using JavaScript to Show Variables When Clicked

I have been working on populating multiple divs with data stored in variables that change when an image is clicked. Here's a snippet of the code within my tag:</p> <pre><code>function displayName(name){ document.getElementById( ...

Vue search button not returning results

Hello, this is my HTML file. <div id="app1" v-cloak> <input v-model="term" type="search"> <button @click="search">Search</button> <p/> <div v-for="post in posts" class="post"> ...

Tips for troubleshooting objects within an Angular template in an HTML file

When I'm creating a template, I embed some Angular code within my HTML elements: <button id="btnMainMenu" class="button button-icon fa fa-chevron-left header-icon" ng-if="(!CoursesVm.showcheckboxes || (CoursesVm.tabSelected == 'curren ...