-1

Solution: There is none. I don't even know why I asked this question, it has absolutely no meaning! I know understand why my channel could bannend :(.

To start with, my website have a header with different symbols that I will link up too.

Here are the steps I want to complete:

  1. Click on a specific buttom inside the header "Contacts" from "home".
  2. Go to "Contacts"
  3. Then click back to "home" from "Contacts".

The problem I get is that the navigation bar must be copied into every file I link up too. How can I prevent this?

I do not know how to code this, can someone please help me?

Dler
  • 54
  • 1
  • 11
  • 1
    You could create a new function in a js file and on every page import the script and call the function to generate the navigation links –  Mar 18 '15 at 12:18
  • possible duplicate of [Include another HTML file in a HTML file](http://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file) – hakre Mar 29 '15 at 19:15

2 Answers2

2

If you are only willing to use html, css & javascript to fix it, then maybe you can achieve that by using angularjs which is a javascript framework and can solve your problem. You create your index.html with all the navigation links and load the external links/ html files in your index.html I created this as an example for you:

http://codepen.io/Edrees21/pen/OPaYVv

<body ng-app="NavigationMenu">
    <div class="container" ng-controller="NavigationController">
        <ul class="nav-menu">
            <li ng-repeat="item in navigationItems"
                    ng-class="{active:isActivePage(item.url)}"
                    ng-click="onItemClick(item)">
                {{item.name}}
            </li>
        </ul>
        <div class="content">
            <div ng-include="currentPage"></div>
        </div>
    </div>
    <script type="text/ng-template" id="your-first-html-file.html">
        <h4>About us</h4>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
    </script>
    <script type="text/ng-template" id="your-second-html-file.html">
        <h4>Links</h4>
        <ul>
            <li>some link</li>
            <li>some link</li>
            <li>some link</li>
        </ul>
    </script>
    <script type="text/ng-template" id="your-third-html-file.html">
        <h4>Contact</h4>
        <p>John Doe</p>
        <p>Long Avenue</p>
        <p>1234567890</p>
    </script>
</body>

Javascript:

angular.module('NavigationMenu', [])
.controller('NavigationController', ['$scope', function ($scope) {
    $scope.navigationItems = [{
        name: 'About us',
        url: 'your-first-html-file.html'
    }, 
    {
        name: 'Links',
        url: 'your-second-html-file.html'
    }, 
  {
        name: 'Contact',
        url: 'your-third-html-file.html'
    }];

    $scope.currentPage = 'your-first-html-file.html';

    $scope.onItemClick = function (item) {
        $scope.currentPage = item.url;
    }

    $scope.isActivePage = function (pageUrl) {
        return pageUrl == $scope.currentPage;
    }
}]);
SED
  • 110
  • 1
  • 8
0

According to my knowledge unless you are using a server side programming language, you have to copy your links to all the pages. If you use programming language like PHP you can create one file for navigation bar and then you can include it to other pages.

Janaka Dombawela
  • 1,337
  • 4
  • 26
  • 49
  • The thing is I am stricted to HTML, Javascript and CSS. Because I will develop the code into phonegap and build an application. So if there is a way to get it work without PHP, I would be happy. – Dler Mar 18 '15 at 12:31
  • After searching for a while I found this answer. It will work. http://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file – Janaka Dombawela Mar 19 '15 at 08:57
  • And pure html way. But not sure wether this will work or not in your case. – Janaka Dombawela Mar 19 '15 at 09:00