Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. HTML5 'Import' failed

HTML5 'Import' failed

Scheduled Pinned Locked Moved Web Development
htmlhelptools
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aks
    wrote on last edited by
    #1

    I need to display a child html page inside the main html page using HTML Import. I tried a sample but it seems to be failing on link.import.querySelector(). The sample code I tried is mentioned below: Can you help me to resolve the problem. Main.html

    <!DOCTYPE html>
    <html>
    <head>
    <link rel="import" href="Child.html">
    </head>
    <body>
    <button id="button1" onclick="onclick">Button1</button>
    <div id="ChildContainer" />
    </body>
    <script>
    button1.onclick = function ()
    {
    alert("Before reading imported files.");
    var link = document.querySelector('link[rel="import"]');

        alert("Before importing Child.");
        var template = link.import.querySelector('Child');
    
        alert("Before cloning contents of Child.");
        var clone = document.importNode(Child.content, true);
    
        alert("Before setting the child to ChildContainer.");
        document.querySelector('#ChildContainer').appendChild(clone);
    
    };
    </script>
    

    </html>

    Child.html

    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    <div id="Child">
    <h3>Sample Text</h3>
    </div>
    </body>
    </html>

    aks

    Kornfeld Eliyahu PeterK A 2 Replies Last reply
    0
    • A aks

      I need to display a child html page inside the main html page using HTML Import. I tried a sample but it seems to be failing on link.import.querySelector(). The sample code I tried is mentioned below: Can you help me to resolve the problem. Main.html

      <!DOCTYPE html>
      <html>
      <head>
      <link rel="import" href="Child.html">
      </head>
      <body>
      <button id="button1" onclick="onclick">Button1</button>
      <div id="ChildContainer" />
      </body>
      <script>
      button1.onclick = function ()
      {
      alert("Before reading imported files.");
      var link = document.querySelector('link[rel="import"]');

          alert("Before importing Child.");
          var template = link.import.querySelector('Child');
      
          alert("Before cloning contents of Child.");
          var clone = document.importNode(Child.content, true);
      
          alert("Before setting the child to ChildContainer.");
          document.querySelector('#ChildContainer').appendChild(clone);
      
      };
      </script>
      

      </html>

      Child.html

      <!DOCTYPE html>
      <html>
      <head>
      </head>
      <body>
      <div id="Child">
      <h3>Sample Text</h3>
      </div>
      </body>
      </html>

      aks

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      I'm sorry to tell you but you have to start to learn HTML/JavaScript from the very beginning, as the place here is to small to explain you all the mistakes (logical and technical) you did in this code... Some probably can write you the proper code, but that will take you nowhere as you clearly do not understand HTML... :((

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      1 Reply Last reply
      0
      • A aks

        I need to display a child html page inside the main html page using HTML Import. I tried a sample but it seems to be failing on link.import.querySelector(). The sample code I tried is mentioned below: Can you help me to resolve the problem. Main.html

        <!DOCTYPE html>
        <html>
        <head>
        <link rel="import" href="Child.html">
        </head>
        <body>
        <button id="button1" onclick="onclick">Button1</button>
        <div id="ChildContainer" />
        </body>
        <script>
        button1.onclick = function ()
        {
        alert("Before reading imported files.");
        var link = document.querySelector('link[rel="import"]');

            alert("Before importing Child.");
            var template = link.import.querySelector('Child');
        
            alert("Before cloning contents of Child.");
            var clone = document.importNode(Child.content, true);
        
            alert("Before setting the child to ChildContainer.");
            document.querySelector('#ChildContainer').appendChild(clone);
        
        };
        </script>
        

        </html>

        Child.html

        <!DOCTYPE html>
        <html>
        <head>
        </head>
        <body>
        <div id="Child">
        <h3>Sample Text</h3>
        </div>
        </body>
        </html>

        aks

        A Offline
        A Offline
        aks
        wrote on last edited by
        #3

        Can any one help me to solve this issue?

        aks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups