Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    repeat html code in lot of pages

    Sup people.
    I'm making the visual part of my web application, all developed in javascript with the support of bootstrap and angularjs.


    The "site" contains fixed stuff, like a complex navigation bar, that is composed by lot of lines of code, that got repeated in each page.

    I'd obviously like to avoid code repetitions, both for ease of change (if i'd like to change a voice in my navbar i should change it in all the pages, argh!), so i was thinking to use something to memorize my code and repeat it while loading the page.

    My choice would be absolutely javascript, no php and if possible no jquery.

    I don't really know how to do it, i should declare a function that, if called, loads my snippet but i really don't know how this should be handled!

    Thank you very much

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,023
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    You know, the easiest way to do this would be to use ".shtml".

    Most servers support this, and it allow your "shtml" pages to easily include other pages.

    Say you have "home.shtml". In it you might write:
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <!-- #include file="header.html" -->
    <div id="nav">
        <!-- #include file="nav.html" -->
    </div>
    ... etc. ...
    </body>
    </html>
    This is a better way than using JavaScript to create tons of HTML content, in my opinion.

    Check with your ISP if they support SHMTL, but I will bet they do.

    If you need a simple-minded demo I can make one.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    May 2013
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i'll have to ask if it could be done, in effects you're right it would be very simple!

    is there any elegant way to do it in javascript too?

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,606
    Thanks
    6
    Thanked 997 Times in 970 Posts
    Quote Originally Posted by yourveins View Post
    is there any elegant way to do it in javascript too?
    No.

    And don’t ask for lengthy explanations because it’s a waste of valuable lifetime.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •