Last active
June 10, 2019 09:30
-
-
Save k-ish/de58297cbb95e6c938abb7cd4c5d6322 to your computer and use it in GitHub Desktop.
外部ファイル読み込み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> writeHeader("./"); </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment