Thanks! You can also do it like this getting from a file, so you dont have to write everything as as a string: the manager js file: class SpecialHeader extends HTMLElement { async connectedCallback() { const htmlFile = 'path/to/your/header.html'; // Replace with the actual path to your HTML file try { const response = await fetch(htmlFile); if (!response.ok) throw new Error('Network response was not ok');
const content = await response.text(); this.innerHTML = content; } catch (error) { console.error('Failed to load the HTML file:', error); this.innerHTML = 'Error loading content'; } } } customElements.define('special-header', SpecialHeader);
Why doesn't a language that is "so modern" have a simplified specification like: " include 'header.js' ", or " require 'footer.js' " Just like the "old", "ancient", "backward" and "dead" PHP?
One Problem though - whatever is written as the title of the page gets applied to all pages. So for example, if on index page - we write 'Welcome to XYZ' even on Contact Us page or privacy policy page, it still says the same. Is there a solution to customize the page title?
Unfortunately, I tried it out and it was not working. I have a nav bar and menu that I want to put on 3 other pages. did the same replaced the nav bar code with the special header and embedded the HTML nav bar code to the js file but no change. thanks the video was clear though.
Subscribing to you right after that. I went for hours on end looking for a tutorial like this. It works perfectly. Thank you so much!
That's great to hear👍
Thanks for subscribing
Simple, elegant, effective solution. Thank you so much!
Glad it helped!
I want to thank you so much for this video !!! I search since days for a video like this 🙌🏾
Thanks! You can also do it like this getting from a file, so you dont have to write everything as as a string:
the manager js file:
class SpecialHeader extends HTMLElement {
async connectedCallback() {
const htmlFile = 'path/to/your/header.html'; // Replace with the actual path to your HTML file
try {
const response = await fetch(htmlFile);
if (!response.ok) throw new Error('Network response was not ok');
const content = await response.text();
this.innerHTML = content;
} catch (error) {
console.error('Failed to load the HTML file:', error);
this.innerHTML = 'Error loading content';
}
}
}
customElements.define('special-header', SpecialHeader);
Css for this? How to implement it? Using styles defined inside the js file or link css external file into the index html template elements?
what will happen for the css? for me mobile navbar isn't working.
Is it possible to put the html header & footer into a separate HTML file?
Why doesn't a language that is "so modern" have a simplified specification like: " include 'header.js' ", or " require 'footer.js' "
Just like the "old", "ancient", "backward" and "dead" PHP?
😄
One Problem though - whatever is written as the title of the page gets applied to all pages. So for example, if on index page - we write 'Welcome to XYZ' even on Contact Us page or privacy policy page, it still says the same. Is there a solution to customize the page title?
Thanky you very much for the video. I have a question: Is it possible to use a link for a CSS file instead of use the "
I do not know is a good idea but what I did was create another CSS file just for the header and footer code and link it to the HTML file works fine
Unfortunately, I tried it out and it was not working. I have a nav bar and menu that I want to put on 3 other pages. did the same replaced the nav bar code with the special header and embedded the HTML nav bar code to the js file but no change. thanks the video was clear though.
Just what I needed - a high speed zip through the process to show it is really not that hard to do.
Thanks for the feedback!
Thanks ❤️💥
You're most welcome!👍
thank you
Welcome!
I thought it was bad practice to use innerHTML. Something about being hackable.
@Music-p4l so it's basically only when it's something like an Input eh?
@@Human_Evolution- yes. If you don't have user-supplied data its not a security risk
@@genchebanu tanx
Great video
Thanks!
Bro it's not working 😢
Your videos don't show up on my subscription feed. :/
I typically upload a new video once a week, usually on Fridays or Saturdays. Thank you for your support
will bootstrap support on in this?
assalamo-alaikum
the same problem
if u find any solution please let me know
It's working with tailwind on my end, so it should be work with bootstrap too