I'm looking to display a text box on my website specifically for users using IE11

I'm following up on my previous post that was put on hold.

I encountered some issues with my website in IE11, which are now resolved. However, I want to implement a code snippet that will display a text box if any similar problems arise in the future.

In my previous inquiry, a user named Zani provided a code snippet that specifically targeted IE11, but unfortunately it's not functioning as expected. In my IE11 Console, I'm seeing the following error message:

SCRIPT5007 : Unable to get property 'style' of undefined or null reference.

Whether I embed this code in a JavaScript file or directly into the HTML, the issue persists.

The problematic code is as follows:

var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
if(isIE11)
  document.getElementById("IDOfYourElement").style.display="block";

While I'm well-versed in HTML and CSS, JavaScript presents a different challenge. I believe there might be an issue related to the usage of style, and I've ensured that the element ID is correctly specified.

EDIT: 1 Here is the current structure of the site:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"</script>
<link href="/CSS/Incompatible.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/Incompatible.js"></script>
    <script type="text/javascript">
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
    if(isIE11)
  document.getElementById("simpleModal").style.display="block";
</script>
</head>
<body>
<button id="modalBtn" class="button" onClick="myModal()">Click Here</button>
<div id="simpleModal" class="modal">
<div class="modal-content">
  <div class="modal-header">
      <span class="closeBtn" onClick="myModalHide()">×</span>
      <h2>Modal Header</h2>
  </div>
  <div class="modal-body">
    <p>Hello...I am a modal</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla repellendus nisi, sunt consectetur ipsa velit repudiandae aperiam modi quisquam nihil nam asperiores doloremque mollitia dolor deleniti quibusdam nemo commodi ab.</p>
  </div>
  <div class="modal-footer">
    <h3>Modal Footer</h3>
  </div>
</div>
</div>
</body>
</html>

Placing the script at the bottom of the HTML page resolves the issue. However, I would prefer having the JavaScript in a separate file. Attempting to use a ready function has not worked successfully.

Answer №1

The error message indicates that there is no element with the specified ID IDOfYourElement. This could be due to two reasons:

  1. There is no element in your document with the ID provided (IDOfYourElement), or
  2. The JavaScript file is being loaded before the elements on the page are fully loaded.

If it's the second case, ensure that your <script> tag is placed at the bottom of your HTML file, or wrap your JavaScript code with a ready function.

UPDATE

To wrap your code in a ready function, you can do so using either jQuery or pure JavaScript. Here are examples for both approaches:

Using Pure JavaScript

window.onload = function() {
  // Your JavaScript code here.
}

Using jQuery

$(document).ready(function() {
  // Your JavaScript code here.
});

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

Adding an icon to indicate that the last reading date is over 24 hours old - how to do it!

Within my HTML, I have the following code snippet: {{hsParametersLastRead.readingDate | date:'medium'}} In my controller, I am using this code: $http.get(hsParametersLastReadEndpoint).success(function (hsParametersLastRead) { $ ...

What is the best way to switch between components when clicking on them? (The component displayed should update to the most recently clicked one

I am facing a challenge in rendering different components based on the navbar text that is clicked. Each onclick event should trigger the display of a specific component, replacing the current one. I have 5 elements with onclick events and would like to re ...

Bootstrap's innovative design for a data grid

I'm currently working on designing a Grid using bootstrap 3. https://i.sstatic.net/DZzcq.png My tools include html5, css, and bootstrap integrated with React.js. The main feature of my project is a data grid (specifically, a Fixed Data Table). ...

Utilizing Javascript to interact with GroupMe API through POST method

I've been working on creating a client for GroupMe using their provided API, but I'm stuck and can't seem to figure out what's going wrong. curl -X POST -H "Content-Type: application/json" -d '{"message": { "text": "Nitin is holdi ...

Displaying AJAX Confirmation in a Popup Window

My form is set up to insert data into a database via an AJAX request. Upon successful insertion, the "rentinsert.php" will display a success message on the page that reads "Your order has been placed". However, I would like this success message to appear i ...

Why is AJAX variable being flagged as undefined when it is clearly defined?

I am currently working on an AJAX call to a JSON page that retrieves variables to create a playlist for an HTML5 music player. I want the playlist data to update every minute as it pulls information from a radio station. My goal is to have only the playl ...

The dimensions of an Angular 2.0 and NodeJS project

After working with Angular 1.x for quite some time, I am now exploring the possibility of migrating to version 2.0. However, I have encountered two main concerns. The specific application server I use does not support NPM integration or transpiling Typ ...

Issue with processing JQUERY getJSON/ajax response

I've encountered an issue while sending a json request to a server. Here is the code snippet: $.getJSON("prod_search.php?type=getCustInfo&custID="+custID, function(json) { alert(json.address); $("#invAddress").html(json.address); $("#curren ...

Encountering an issue when attempting to store image links in the database using PDO

One idea that I have is to create an image uploader system that sends the image to the 'upload' folder and saves the link to the database. I encountered errors in my 'images.php' file. Can anyone assist me with resolving these issues? ...

Enhancing Bootstrap modals with dynamic content and integrating Ajax for dynamic data retrieval in Laravel

I am facing some challenges while coding in Laravel, specifically with passing data to a modal (using the Bootstrap framework) and sending data to an Ajax post request. I have an array of items with an 'id', a 'name', and 'content& ...

The error message TS2304 is indicating that the name 'Set' cannot be found in electron-builder

I am trying to utilize the AppUpdater feature in electron-builder for my Electron Application. Upon importing the updater in my main.ts file: import { autoUpdater } from "electron-updater" An error is triggered when running the application: node_module ...

The tab navigation feature is experiencing issues in Internet Explorer versions 7 and 8

I have successfully implemented a tab menu that functions well in Chrome and IE 9,10. However, it does not seem to work in IE 7 or 8. I am at a loss regarding what changes need to be made to my code. Could anyone provide assistance? Link to Code Example ...

Async.waterfall: The callback has already been invoked in a node.js environment

I acknowledge that there are similar questions addressing the same issue I am facing. Despite following the solutions provided in those threads, I have been unable to resolve the error I encounter when trying to implement async.waterfall(). The specific e ...

Why is my component not utilizing the implementation in this Jest mock?

I'm currently attempting to run tests on a React component using Jest. Within the component, there is a required module that acts as a factory function returning an object of functions. //tracker.js export default () => { track: click => doso ...

Enhancing the styling of checkboxes using CSS and Javascript

My Javascript skills have been put to the test with a simple code snippet that customizes checkboxes by hiding them and using background images in CSS to display checks and unchecks. It's a neat trick, but I'm wondering if it's HTML/CSS comp ...

How to Deactivate Horizontal Scrolling Using CSS in WordPress

Hey there, I'm currently working on a WordPress blog and facing an issue. Here's the link to my problem: When I resize the browser (X-Axis) to a minimum, like when using a mobile device, I noticed that I can scroll to the right in the Content se ...

Move objects into the designated area to access all items located inside

How can I retrieve all the elements inside the droppable area? For example, if I drag ten elements to the droppable area and then remove three, how can I identify which elements are still inside the droppable area when a button is clicked? Has anyone enco ...

Learn how to decrypt messages using CryptoJS AES with a successful Ruby demonstration

Decoding AES encrypted messages with Ruby is possible using the following code: require 'openssl' require 'base64' data = "IYkyGxYaNgHpnZWgwILMalVFmLWFgTCHCZL9263NOcfSo5lBjAzOZAtF5bF++R0Bi+9c9E+p3VEr/xvj4oABtRWVJ2wlWzLbYC2rKFk5iapFhb7 ...

Why does this function properly on every browser except for Opera?

I have implemented a script that allows me to replace the standard file upload input with a custom image. The script also ensures that an invisible 'browse' button appears underneath the mouse pointer whenever it hovers over the custom image. Thi ...

Align the number of an Unordered List to the left

Exploring UN-ordered lists in HTML has led me to wonder if it's possible for dynamically generated ul tags to display like this: * Hello * Hi * Bi * Name * Ron * Mat * Cloth * Color * Red When I ...