Skip to content

Instantly share code, notes, and snippets.

@vovs03
Created November 22, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vovs03/694aa9a65179932e09bfcb9ed08df36c to your computer and use it in GitHub Desktop.
Save vovs03/694aa9a65179932e09bfcb9ed08df36c to your computer and use it in GitHub Desktop.
HTML Imports
<template>
<h1>Hello World!</h1>
<!-- Img is not requested until the <template> goes live. -->
<img src="world.png">
<script>alert("Executed when the template is activated.");</script>
</template>
<!DOCTYPE html>
<head>
<link rel="import" href="import.html">
</head>
<body>
<p>Проверка работы - ниже вставка, импорт.</p>
<div id="container"></div>
<script>
var link = document.querySelector('link[rel="import"]');
// Clone the <template> in the import.
var template = link.import.querySelector('template');
var clone = document.importNode(template.content, true);
document.querySelector('#container').appendChild(clone);
</script>
</body>
</html>
@vovs03
Copy link
Author

vovs03 commented Nov 22, 2017

Errors:

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

  • Uncaught TypeError: Cannot read property 'querySelector' of null
    at index.html:13

@vovs03
Copy link
Author

vovs03 commented Nov 22, 2017

пробовал локально, не работает, другой вариант отправил на сервер, код работает

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment