Skip to content

Instantly share code, notes, and snippets.

@k-ish
Last active June 10, 2019 09:30
Show Gist options
  • Save k-ish/de58297cbb95e6c938abb7cd4c5d6322 to your computer and use it in GitHub Desktop.
Save k-ish/de58297cbb95e6c938abb7cd4c5d6322 to your computer and use it in GitHub Desktop.
外部ファイル読み込み
function writeHeader(rootDir){
$.ajax({
url: rootDir + "/header.html", //パスはcommon.jsが読み込まれたHTMLファイルが基準
cache: false, //キャッシュを利用するか(
async: false, //非同期で読み込むか
success: function(html){
html = html.replace(/\{\$root\}/g, rootDir);
document.write(html);
}
});
}
<header>
<nav>
<ul>
<li><a href="./{$root}index01.html"></a></li>
<li><a href="./{$root}index02.html"></a></li>
<li><a href="./{$root}index03.html"></a></li>
<li><a href="./{$root}index04.html"></a></li>
<li><a href="./{$root}index05.html"></a></li>
</ul>
</nav>
</header>
<script type="text/javascript"> writeHeader("./"); </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment