+ 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

7th Mar 2021, 11:53 PM
Ginfio
Ginfio - avatar
3 RĂ©ponses
+ 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) ^^
8th Mar 2021, 12:10 AM
visph
visph - avatar
+ 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!
8th Mar 2021, 11:04 AM
Schindlabua
Schindlabua - avatar
+ 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.
7th Mar 2021, 11:56 PM
Ginfio
Ginfio - avatar