简体   繁体   中英

Splitting HTML file doesn't work

I'm trying to build very simple web page (one page , spited into 2 parts, each part will have it's 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;
}

I want that Welcome.html file will get the top content from external html file

Top.html


<html>

  <head>    
  </head>

  <body>
      Test -> TOP

  </body>
</html>

But is seems that there is no request for Top.html file 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 guess I'm missing something very easy, but can't find the mistake.

Kindly checkout templatesjs ; It will help insert html inside another html.

I'm not sure what "w3-include-html" is, but if it does what it is supposed to do (based on the name), then try changing its value from "/Top.html" to "/Top". Or, alternatively, try changing the url route "/Top" to "/Top.html" in your express app.

One side note: Your included html ("Top.html") should not be a complete html. Try removing html, header and body tags. It should be a fragment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM