0

If I have two html pages: index.html and embed.html. In embed.html, I have a random html page. However, I need to embed it inside index.html. I used this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div style="width:100%; padding-bottom:56.25%; position:relative; border: 2px solid black;">
        <iframe src="C:\\Users\\User\\OneDrive\\Desktop\\Web prog\\embed.html" style="position:absolute; top:0px; left:0px; 
        width:100%; height:100%; border: none; overflow: hidden;"></iframe>
      </div>
  </body>
</html>

In the src attribute, I put the path of the embed.html page.

When I run index.html. This is what I get in the dev tools:

index.html:12 Not allowed to load local resource: file:///C://Users//User//OneDrive//Desktop//Web%20prog//embed.html

Nothing appears in the index.html except the border I specified of the iframe tag

How can I make this work?

MaxiGui
  • 6,190
  • 4
  • 16
  • 33
Najwa K. Semdina
  • 31
  • 1
  • 1
  • 4
  • `C:\\...` is not a correct path as the error tells you. Also you need to give the webpage read-permissions – tacoshy Nov 24 '21 at 09:41
  • Does this answer your question? [How can I create a link to a local file on a locally-run web page?](https://stackoverflow.com/questions/18246053/how-can-i-create-a-link-to-a-local-file-on-a-locally-run-web-page) – tacoshy Nov 24 '21 at 09:42
  • If index.html and embed.html is in the same directory, try this src in your iframe: `src="./embed.html"`. – LSE Nov 24 '21 at 09:51

1 Answers1

1

If the html is in the same directory, use:

<iframe src="embed.html">

If the html is in a parent directory, use:

<iframe src="../embed.html">

Or if you want you can use the absolute path:

<iframe src="file:///c:\Users\User\OneDrive\Desktop\Web prog\embed.html">
BeanBoy
  • 326
  • 2
  • 10