admin管理员组

文章数量:1290136

We have an offline set of HTML pages we're working with using HTML5 document type. We want to include our sub-navigation via a <script src="____"> but for some reason it's not including. Is there some other method of including the file without needing server-side assistance somewhere?

Because of how we're delivering these files to the client we must work offline, but it would seriously suck to have to update 100 files due to a simple sub-nav change that could be globally included via Javascript somehow.

We have an offline set of HTML pages we're working with using HTML5 document type. We want to include our sub-navigation via a <script src="____"> but for some reason it's not including. Is there some other method of including the file without needing server-side assistance somewhere?

Because of how we're delivering these files to the client we must work offline, but it would seriously suck to have to update 100 files due to a simple sub-nav change that could be globally included via Javascript somehow.

Share Improve this question edited Sep 10, 2010 at 19:41 ndim 37.9k12 gold badges49 silver badges58 bronze badges asked Sep 10, 2010 at 19:18 Will AshworthWill Ashworth 1,0883 gold badges14 silver badges29 bronze badges 1
  • As a further example, let's imagine we're totally offline with our HTML (no server) as if we're putting these onto a CD-Rom or DVD. I'm guessing there may be some clever trick with Ajax that I'm not thinking of just yet. – Will Ashworth Commented Sep 10, 2010 at 19:22
Add a ment  | 

2 Answers 2

Reset to default 10

You could put an empty div

<div id="navigation"></div>

And then "load" that with jQuery

$("#navigation").load("path/to/nav/file.html");

External HTML code can be included via .js file. Here is an example:

<!DOCTYPE html>
<html>
    <head>
    <title>Main Page</title>
        <script type="text/javascript" src="include_html.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            paragraph();
        </script>
    </body>
</html> 

Contents of include_html.js

function paragraph()
{
        document.write("<p> This is an HTML paragraph </p>");
}

本文标签: javascriptOffline HTML5 html pagesneed to include file into another fileStack Overflow