Search code examples
javascriptfirefoxweb-componenthtml-importshtml5-template

getting error link.import is null in firefox


<link rel="import" href="header.html">
 <link rel="import" href="footer.html">

 <script>
          var link = document.querySelector('link[href*="header"]');
          var template = link.import.querySelector('template');
          var clone = document.importNode(template.content, true);
          document.querySelector('#nav').appendChild(clone);
 </script>
 <script>
          var link = document.querySelector('link[href*="footer"]');
          var template = link.import.querySelector('template');
          var clone = document.importNode(template.content, true);
          document.querySelector('.footer').appendChild(clone);
</script>
I saprated header and footer, and i have to call in all pages, am using HTML5, but header and footer shown in only Google Chrome browser, FireFox and safari dosen't shows header and footer and gives error like TypeError: link.import is null


Solution

  • Only Chromium/Blink-based browsers have shipped <link rel=import> HTML Imports support. Firefox doesn’t support HTML Imports unless you enable the dom.webcomponents.enabled flag:

    Firefox will not ship HTML Imports. See this Hacks blog post for more information. You can still use HTML Imports in Firefox by enabling the dom.webcomponents.enabled flag. If you don't want to enable the flag, you can use a polyfill such as Google's webcomponents.js.

    The current HTML Imports spec is basically dead at this point, stalled since February 2016 at just Working Draft status, and won’t be advancing any further along the W3C standardization track.

    So no other browsers will ever be implementing that old HTML Imports spec. Instead at some point a new spec will be developed—one that hooks into ES6 Modules and the underlying machinery of <script type=module> “module scripts” as now defined in the HTML spec.