简体   繁体   中英

jsp include function in html5?

Is there a function in html5 that acts like a jsp include?

Something like which can be added automatically to a page by using a single source.

Are you looking for something like an iframe ?

No, if you need such behavior use a server-side language such as PHP. If you cannot do this, you have to use JavaScript to "include" another page by fetching it via AJAX and then adding it to the DOM.

PHP example:

<?php include 'header.html'; ?>
<h1>hi</h1>
<p>blah blah</p>
<?php include 'footer.html'; ?>

JS example using jQuery :

<!doctype html>
<body>
    static stuff
    <div id="content"></div>
    <script>
        $('#content').load('content.html');
    </script>
</body>

Do not use the JS solution like this. It will make the page unusable by anyone who does not have a JS-capable browser - search engines for example.

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