3

I'm trying to import header.html for avoiding file duplication. But in this situation, I can't use PHP. This is the head section of index.html file,

<script
        src="https://code.jquery.com/jquery-3.3.1.js"
        integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
        crossorigin="anonymous">
</script>
<script>
    $(function(){
        $("#header").load("header.html");
        $("#footer").load("footer.html");
    });
</script>

The body section I have called my header.html as follows,

<body>
  <!-- include Header -->
  <div id="header"></div>
  <!-- end include header -->
</body>

The header is including fine but after the header included the dropdown lists become unclickable. In this image I cant click about us dropdown list

When I go to inspect elements there are following errors, enter image description here

0

4 Answers 4

9
+50

One possible reason for your problem would be that if you already have <html><head><body> tags in all header.html, footer.html and your master page. When you import those sub pages in your master page all those tags will come along with contents. If its true delete those tags from your sub pages because your master page should only have one of specific tags

2

1) Remove the following tags from header.html and footer.html

<html>
    <head>
    </head>
    <body>
    </body>
</html>

2) Regarding Slick error please make sure you are not calling the init twice, best way would be

$('.selector').slick();
-1
$(document).ready(function() {

    $.get("header.html", function(response){

        $('#header').html(response);

    });

})
3
  • 1
    this is not php.its jquery
    – R.tbr
    Mar 5, 2019 at 9:07
  • 1
    this script send a request to header.html and get all data of this page and write returned data to #header
    – R.tbr
    Mar 5, 2019 at 9:11
  • I'll try with this. Thank you @R.tbr Mar 5, 2019 at 11:40
-1
  <?php include_once('header.html');?>

    <div id="header"></div>

    <?php include_once('footer.html');?>
3
  • 2
    I have mentioned that I don't need a suggestion with PHP Mar 5, 2019 at 9:05
  • @DebanjanB please read the question again, I have mentioned that I can't work with PHP in this situation. Mar 5, 2019 at 11:38
  • 2
    @Mr.Semicolon Irrespective of the PHP factor, this answer landed in the VLQ queue. So we have asked the answerer to add the required verbatim. Mar 5, 2019 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.