Path to file: getting to the root directory

I tested a solution using document.location.toString() on linux, but I imagine the following could work on a Window’s machine.
At the top of the footer.js file, put:

const rootDir = 'file:///D:/'; // might have to use 'file:\\D:\`

Then in the template literal, the img element would be:

<img src="${rootDir}components/HappyBook.jpg" alt="happy book" style="width: 40px; height=40px">

Thank you, @RandellDawson !!!
For the case of Drive Z:, footer.js beginning with:

const footerTemplate = document.createElement('template');
 const rootDir = 'file:///Z:/'; 
footerTemplate.innerHTML = ` 

and

      <li><img src="${rootDir}components/HappyBook.png" alt="..."></li>
      <li><a href="${rootDir}about.html">About</a></li>

worked for me!
For localhost, I used:

 const rootDir = 'http://localhost/test-2/'; 

and it works as well.
Thank you!,
And I thank @hbar1st as well!

PS: Please let me know if you think of any other way to include files with HTML - CSS only.
Thanks again.

With localhost, I would not use the hardcoded variable. Instead, I would use the absolute path version. The less hardcoding in code the better for maintenance purposes.

My localhost demonstrates the same problem:
without the ~~ const rootDir ~~~

<a href="/about.html">About</a>

looks for C:\about.html :frowning:

iframe and object both act as a new browser inside of the calling browser, and any links there open in the same window. is there any way to have those links replace the calling browser?

Thanks

For the record, @RandellDawson and @hbar1st
I now have 2 .js without const rootDir.
This works with my localhost and with direct load from Firefox.

NOTE: the extra “.” are from FCC’s editor - I only use two.

The first for root-level is called as <script src=“components/footer.js”></script>
and has links as < a href=“about.html”>About</a>

The second for level2 is called as <script src=“…/components/footer.js”></script>
and has links < a href=“…/about.html”>About</a>

I will use this until something better comes along.

Thanks again for your help.
– Fred