When compiled on a device, Cordova is not utilizing CSS and JS files

I am currently in the process of developing an app using Cordova with an HTML file. However, after building the app, I encountered issues where it is not incorporating CSS and does not seem to be utilizing JavaScript.

  <!doctype html>
  <html lang="en">
    <head>
        <script>
        function displayContent() {
           document.getElementById('welcomeDiv').style.display = "block";
        }
        </script>
      <meta charset="utf-8">

      <title>MyApp</title>

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
      <link rel="stylesheet" href="./main.css">
    </head>

    <body>
        <input type="button" name="answer" value="Show Content" onclick="displayContent()" />
        <div id="contentArea"  style="display:none;" class="response_section" > WELCOME</div>
        <div class="jumbotron" id="abc">
          <h1 id="def">Wednesday 20/4 Week 16:</h1>
          <h1 id="ghi">
             <small>Math GymNorwegian</small>
          </h1>
        </div>
        <div class="jumbotron" id="abc">
          <h1 id="ghi"><small>Homework for Thursday:</small></h1>
        </div>
        <div class="jumbotron" id="xyz">
          <h1 id="def">No homework today!</h1>
        </div>
    </body>
   </html>

The CSS files I am using are located within the WWW folder, along with the index.html file. Additionally, some CSS styles are being imported from bootstrap as well. I am uncertain if this could be causing the issue. Furthermore, the JavaScript code placed in the header section does not execute as expected, resulting in the div not displaying properly. Could this be due to a problem with CSS compatibility, especially given the use of style.display method?

Thank you!

Answer №1

I encountered a similar issue when placing the script in the head section and calling the function from an HTML element, just like you did. However, I resolved it by moving the script to the bottom of the page, like so:

...
<div class="jumbotron" id="nbm">
          <h1 id="sub">ayylmao no homework</h1>
        </div>
        <script>
        function showDiv() {
           document.getElementById('welcomeDiv').style.display = "block";
        }
        </script>
    </body>
   </html>

Otherwise, the script would have been executed after the DOM had finished loading!

Answer №2

Ensure that the location of your css file and index file is correct

if you are referencing the css file in the wrong way

<link rel="stylesheet" href="./main.css">

If both your index file and css file are in the same folder

www/index.html & www/main.css

Then link it like this

<link rel="stylesheet" href="main.css">

or if the css file is located in a subfolder named style or elsewhere

<link rel="stylesheet" href="style/main.css">

This approach should work for you

Updated

index.html

<head>
    <meta charset="utf-8">
    <title>InstaPlan</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="style/main.css">
    <script src="cordova.js"></script>
    <script src="js/main.js"></script>
</head>
<body>
    <input type="button" name="answer" value="Show Div" onclick="showDiv()" />
    <div id="welcomeDiv"  style="display:none;" class="answer_list" >WELCOME</div>
    <div class="jumbotron" id="nbn">
        <h1 id="sub">Onsdag 20/4 Uke 16:</h1>
        <h1 id="mid">
            <small>Gym MatteNorsk</small>
        </h1>
    </div>
    <div class="jumbotron" id="nbn">
        <h1 id="mid"><small>Lekser til Torsdag:</small></h1>
    </div>
    <div class="jumbotron" id="nbm">
        <h1 id="sub">ayylmao ingen lekser</h1>
    </div>
</body>

Created folder for style in www folder

style/main.css

.jumbotron h1{
   font-size: 12px;
   text-decoration: underline;
   font-weight: 200;
}

Created folder for js in www folder

js/main.js

function showDiv() 
{
    document.getElementById('welcomeDiv').style.display = "block";
}

It's working for me with the bootstrap css and my custom css

Please give this a try and let me know if it works for you as well.

Answer №3

If you are encountering difficulties, it could be due to the cordova-whitelist problem. To resolve this, take a look at the cordova-whitelist plugin for guidance on how to include external css files.

https://github.com/apache/cordova-plugin-whitelist

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

Finding the difference or sum within an array to identify the two numbers that produce a new array

In order to clarify, I am looking for a method to identify the two smallest numbers in a sorted array that will result in a specific number when subtracted. The process can be broken down into the following steps: Iterate through the array and designate ...

Exploring Angular2: The Router Event NavigationCancel occurring prior to the resolution of the Route Guard

My application has routes protected by an AuthGuard that implements CanActivate. This guard first checks if the user is logged in and then verifies if certain configuration variables are set before allowing access to the route. If the user is authenticated ...

Updating the database table using javascript

I am looking to dynamically update my database based on a condition in JavaScript. Currently, I have been using the following approach: <a href="#" onclick="hello()">Update me</a> <script> function hello(smthing) { if(smthing == true) ...

hyperlink triggers spacing problem in Internet Explorer

When displaying a paragraph of text, I add a "read more" link at the end if the text exceeds a certain length. However, in Internet Explorer (IE), the line with the link appears separated from the line above, creating an awkward look. To see where this is ...

Setting the height of columns in a Bootstrap panel to 100%

Is there a way to achieve 100% height for all three columns even without content? Check out this JSFiddle: <div class="row"> <div class="col-md-12"> <div class="shadow panel panel-default"> <div class="blue white-bord ...

I am encountering errors when running NPM start

After setting up my webpack, I encountered an error in the terminal when attempting to run the code npm start. The specific error message was related to a module not being found. Can someone please assist me with resolving this issue? > <a href="/c ...

Tips on integrating JavaScript with embedded Ruby code

I am attempting to generate a flash message that displays after a user clicks a link in my js.erb file. $('a').click(function(){ <% flash.now[:alert]= "Successfully added "%> this.innerHTML <% "to cart" %> }) M ...

Ensure that the bar width in react-chart-js-2 remains consistent regardless of the number of bars displayed

Currently, I am developing a React Chart JS component that displays a set of horizontal bars. My objective is to maintain the width of the bars at a consistent size regardless of the number of bars present (e.g., all bars at 30px). However, when additiona ...

Make CKEDITOR cease the unwrapping of blocks

Imagine I have the following block markup: <div class="block"> <a href="/"> <div class="divInside"></div> <img src="/bla" /> <p>Paragraph</p> </a> </div> HTML5: explain ...

Building Your Initial HTTP Server using Node.js

Hey everyone, I'm relatively new to node.js but have made some progress. Following the steps in this tutorial, I was able to create my first "example" server. However, there are a few things that I don't quite understand. Could someone please exp ...

The values in my JavaScript don't correspond to the values in my CSS

Is it possible to retrieve the display value (display:none; or display:block;) of a div with the ID "navmenu" using JavaScript? I have encountered an issue where I can successfully read the style values when they are set within the same HTML file, but not ...

View content from a text file on a webpage

Hi everyone, I could really use some assistance with a project I'm currently working on. As someone who is new to programming, I am facing a challenge. My goal is to showcase the contents of a plain text file on a webpage. This text file, titled titl ...

Improving the innerHTML syntax

I am looking for the correct syntax to add content to an element using innerHTML. Here is an example that isn't working as expected: openNewWindow: function(content) { popupWin = window.open(content, 'open_window', 'menubar, ...

Guide to dynamically refreshing a section of the webpage while fetching data from the database

I'm currently developing a website using PHP & MySQL where some queries return multiple records. Each record has its own dedicated page, allowing users to navigate between them using arrows. So far, everything is working smoothly. However, I've ...

wrap <td> data in a link with vue depending on certain conditions

I'm trying to customize the display of a particular table cell td. I want to show the data in a link if a certain condition is met, and if not, just show the data as text. However, I'm encountering some difficulties in implementing this. I have ...

Tips for increasing the width of a button within an HTML table heading

I'm attempting to make a button within a table <th> expand to the full width and height of the header column, even if a table cell in the same column is larger than the text. If I set the width to 100% in CSS, the button ends up matching the siz ...

How can I retrieve the Sequelize results in the form of a 2D array rather than an array of objects?

I have a situation where I am using the Sequelize query() method like this: const sequelize = new Sequelize(...); ... // IMPORTANT: Cannot modify this query const queryFromUser = "SELECT table1.colname, table2.colname FROM table1 JOIN table2 ON/*...*/ ...

Using ReactJS, the for loop can be utilized to dynamically create buttons and assign variables based on the integer being iter

I need some help with ReactJS. I'm trying to generate 10 buttons using a for loop and assign a variable with the iteration number, but when I use the function setMqty(i), it always returns 11 for all buttons. Can anyone help me figure out the correct ...

What is the best way to add a new project and make updates to an existing project within an array?

Looking to add a new project and update existing projects within an array. Here's my plan in pseudo-JSON format. How can I update Project A in MongoDB? { _id : ..., userName: milad , projets : [ { .. projectId, pName, location .... A }, ...

The issue arises when trying to use ::v-deep in conjunction with v-dialog's content-class when using scoped scss

I've been working on styling the content of the Vuetify dialog component and have been using the content-class prop along with scoped styles to achieve this. Can someone explain the difference between the styles provided below? And also, any tips on h ...