Having trouble dividing an HTML file?

Currently, I am working on creating a very basic web page that is divided into two parts. Each part will have its own HTML file:

Welcome.html & Welcome.css:

<html>

    <head>
        <link rel="stylesheet" type="text/css" href="Welcome.css">
    </head>

    <body id="bodyTag">

     <script type = "text/javascript"  src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>       
      <script type = "text/javascript">
         $(document).ready(function(){            

         });
      </script> 

       <div id="top" w3-include-html="/Top.html">

       </div>

       <div id="bottom">
            bottom
        </div>

    </body>
</html>


#bottom {    
    height: 50%;
    background-color: blue;
}

#top {    
    height: 50%;
    background-color: orange;
}

The goal is for Welcome.html to fetch the top content from an external HTML file:

Top.html


<html>

  <head>    
  </head>

  <body>
      Test -> TOP

  </body>
</html>

However, currently, there does not seem to be any request being made for Top.html in the Node.js Log:

var express = require('express');
var app = express();
var fs = require('fs');
var bodyParser = require('body-parser');

app.use(bodyParser.json())


/* 
 *  Home page
 */
app.get('/', function (req, res) {
   clearLogScreen();
   console.log("[/] Got request for '/'");
   res.sendFile( __dirname + '/Welcome.html');   
})


app.get('/Welcome.css', function(req, res) {
  console.log("[/Welcome] Got request for 'Welcome.css'");
  res.sendFile(__dirname + "/" + "Welcome.css");
});

app.get('/Top', function(req, res) {
  console.log("[/Top] Got request for 'Welcome.top'");
  res.sendFile(__dirname + "/" + "Top.html");
});


/* 
 *  Startup
 */
var server = app.listen(8081, function () {
   var host = server.address().address
   var port = server.address().port

   // start
   console.log("-----------------------------")  
   console.log("Dirname: " + __dirname);
   console.log("App listening at http://%s:%s", host, port)
})

I believe I must be overlooking something simple, but I am unable to identify the error.

Answer №1

Feel free to take a look at templatesjs; this tool enables the insertion of HTML within other HTML content.

Answer №2

I'm not completely familiar with the functionality of "w3-include-html," but if it performs as its name suggests, consider modifying the path from "/Top.html" to just "/Top." Alternatively, adjust the URL route in your express app from "/Top" to "/Top.html."

It's worth noting that the included html file ("Top.html") should not contain a complete HTML structure. Remove any html, header, and body tags so that it functions as a fragment.

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

Utilize Tailwind CSS in React to dynamically highlight the active navigation item on click

Check out my navigation bar code: <nav className="bg-white shadow dark:bg-gray-800"> <div className="container flex items-center justify-center p-6 mx-auto text-gray-600 capitalize dark:text-gray-300"> <Link ...

Creating an HTML tag from Angular using TypeScript

Looking at the Angular TypeScript code below, I am trying to reference the divisions mentioned in the HTML code posted below using document.getElementById. However, the log statement results in null. Could you please advise on the correct way to reference ...

Managing active dropdown menus in VueJS

I'm having trouble figuring out why my navigation menu and method to open subitems on click are not working correctly. [![dropdown_menu][1]][1] new Vue({ el: '#app', data: { //menu "menu_title": "a", "child_ro ...

Unable to capture screenshot of hovered element using Cypress

Having an issue with taking a screenshot of an element with a hover effect. The screenshots always come out without the hover effect applied. tableListMaps.lineWithText('Hello world', 'myLine'); cy.get('@myLine').realH ...

Order of operation when running a Node.js application

I've always been curious about this and never have come across a satisfactory answer. Let's explore this scenario: var toEmail = ''; if(j==1) { toEmail="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail= ...

How to Pass and Execute Asynchronous Callbacks as Props in React Components

I'm curious about the correct syntax for passing and executing async calls within React components. Specifically: Many times, I'll have a function that looks like this: const doAsync = async (obj) => { await doSomethingAsync(obj) } ...and ...

React does not always remove event listeners when using the useEffect hook's return callback

I have a functionality in my component where it initializes a key event listener. This event is supposed to trigger an API call to fetch random data. useEffect(() => { const keyUpEvent = (event) => { if (event.code === "Enter") { ...

Optimizing Window Width with React.js and CSS

I'm currently in the process of building a responsive website with react. I am utilizing CSS stylesheets for styling and have used @media queries to ensure responsiveness. However, I've encountered an issue while testing in Chrome where the elem ...

Creating an Editor for Input Text Field in HTML: A Step-by-Step Guide

In the vast landscape of JS libraries that can achieve this function, like Trumbowyg and more. However, prior to my rails project displaying that slim version, I need to ensure JavaScript is properly escaped! Therefore, I need to create an editor using o ...

challenges faced when sending requests through nginx and express router

I've been working on setting up two Node/Express sites behind Nginx. Despite trying various solutions from forums, I'm only getting partial success. My goal is to have: - one domain with two Node/Express apps 1.) node.dev/site3 2.) node.dev/site ...

What is the best way to center align an element while having another element situated directly below it?

I want to create a grid of "clock" elements, with five clocks in each row. Below each clock, I'd like to display the DAY and DATE centered with the clock (day on top line, date below). Since I'm new to html/css, I appreciate your patience. Here&a ...

Is there a way to create a PHP function that can process an AJAX request and return a boolean value?

After some testing, I discovered that when the code snippet below is executed within my PHP function to manage an AJAX call: session_start(); if ( $_POST['animal'] != $_SESSION['animal'] ) die(json_encode(false)); Upon returning to th ...

Is it possible to conceal an HTML form once it has been submitted

I have a form on my website that sends the entered information to a PHP script which then emails me the details. I've implemented JavaScript form validation and jQuery Ajax to ensure the page doesn't need to be reloaded. Here is the HTML code fo ...

issues with the styling and scripts within the jsp document

During my project work, I encountered an issue with the front end as shown in the image below. Upon loading the project, all styles and scripts disappear completely. How can I resolve this issue promptly? I attempted to update the jQuery version by replac ...

What is the best way to prevent a jQuery hover event from adding a text-shadow to the CSS?

Currently, I am facing an issue with a jQuery event that triggers a text-shadow effect: $(".leftColumn").hover(function (){ $(".leftColumn h2").css("text-shadow", "0px 2px 3px rgba(0, 0, 0, 0.5)"); },function(){}); The problem arises when the text-shad ...

What are the steps for skipping, sorting, and limiting with dynamoose?

After being familiar with MongoDB and mongoose, I am now exploring dynamoose for my app. In order to replicate the below-shown mongoose query using dynamoose, how can I write it? Specifically, I want to achieve the same functionality as the following mong ...

Accessing the session object within an Express middleware function is crucial for

This is my unique Express middleware setup: var app = express() .use(express.cookieParser()) .use(express.session({secret: 'HiddenSecret'})) .use(express.bodyParser()) .use(function displaySession(req, res, next) { consol ...

I'm confused as to why only one of my HTML pages is accepting my CSS styling - not sure what's going on

I am facing an issue where the CSS styles are only being applied to one of the HTML pages I created. Despite checking my code multiple times, everything seems to be correct. All the necessary files are saved on my laptop in the same folder for the website. ...

The session name has not been properly defined

Sorry for any errors in translation. I'm facing an issue where the session name I insert is coming up as undefined. However, when I manually enter the username, everything works fine. View Image <? php session_start (); echo var_dump ($ _SESSION ...

Upload files via Ajax request is required

I am in the process of trying to upload a binary file to a server while avoiding a full page refresh when the server responds. I must admit, I am not well-versed in this area and I understand if my approach needs some adjustments. This is how I have appro ...