+ 1
would using JS (nav.innerHTML = â...â) be a bad idea for putting nav and footer on multiple pages?
The goal: To make it to the point so I donât have to copy and paste the nav and footer content and paste on every single page that I want to have a nav. This can take a long time especially if I have a lot of pages. So hereâs what Iâm thinking: Look at the code. Donât worry much about the syntax. But in the code what Iâm doing is made a <nav> tag at the top and <footer> at the bottom. So on all the pages that ok want to have the footer, I just put the two tags, and link to the nav_and_footer.JS script. https://code.sololearn.com/WGUA600Dfkif/?ref=app
3 Answers
+ 2
I think that if you could avoid JS it is better, as not all browsers have JS support or JS enabled...
however, if you make pages wich requires JS, it's not a bad idea (nowadays, a lot of site doesn't works without JS enabled, coz the use of 'modern' framework wich build parts or entire page dynamically on client side, and so disallow browser without JS) ^^
+ 2
It's fine for experimenting but really this is where you would use frameworks such as React, or ASP.NET, or tons of others. They can do this sort of stuff but with many convenience functions. You will find that your approach can get very messy very quickly.
using .innerHTML is also a security risk, for example you could inject malicious javascript code into your site this way, without you realizing it, if you are not careful.
But I mean for small personal projects anything goes, so more power to you!
+ 1
Iâve asked a similar question recently, and CalviŐČ showed me a way to do it using class and consteuctors, but im yet to understand classes and constructors.
I was thinking I could just fo it using nav.innerHTML, and footer.innerHTML.
But no body really mwntions this idea, but me, so iâm wondering if itâs because itâs a bad idea.