简体   繁体   中英

HTML5 Importing external local html file in index.html

Earlier I somehow managed to load html code from external html file from my index.html using

<head>
    <link rel="import" href="html/html_snippets.html">
</head>

and then find it with

var mySnippet = $(".foo").html();

but now I started to receive errors about CORS policy:

Access to Imported resource at 'file:///path/html/html_snippets.html' from origin 'file://' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access.

and I can't make it work.

How can I override this, I need to have html snippets in external file and load them just once at startup, and work on them later.

Yes, HTML have option to include the html file . The syntax is like

<div w3-include-html="content.html"></div>

<script>
w3IncludeHTML();
</script>

For reference http://www.w3schools.com/howto/howto_html_include.asp

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