Skip to content Skip to sidebar Skip to footer

Creating And Structuring The Index Page

I have a test website www.lemonbrush.com is has the two menu items 'Home' and 'About'. When we click on the 'About' menu, the About page is loaded dynamical, which is great, but wh

Solution 1:

When you're clicking the menu item you are updating the page with the data, but when you are going to the link directly you are just getting the data. one way around this is to have common elements for the page, ie. navigation menus, In a javascript file and then use a script tag with a link where you want it on the page.

Solution 2:

so, since i thought it would be nice for my project, to have a usable browser history and bookmarkable subpages, i yesterday tried the approach from my comments of the OP.

step 1: change the anchors in your navigation bar to something like that:

<ahref="#index">home</a><ahref="#about">about</a>

needles to say, that they don't need to be inside the same parent element. those links could be anywhere.

step 2: remove the on click handler from your script, that reacts on the navigation bar clicks!

step 3: create a function, to listen to the onhashchange event. (this has to be done once, on the main html page)

//create a function for the onhashchange eventwindow.onhashchange = function()
{
    //check if a location hash is usedif(window.location.hash != null) 
    { 
        //store current location hash in a variable
        requestedPage = location.hash;
        //remove the '#' from the location hash value
        requestedPage = requestedPage.replace('#','');

        //load content from subpage into your content frame
        $('#contentFrame').load('./' + requestedPage + '.html', function( response, status, xhr ) 
        {
            //catch 'file not found' errors and load start pageif ( status == "error" ) {
                $('#mainPanel').load('./start.html');
            }
        });
};

for your page, you have of course to adapt, use the correct selectors and the correct file names.

you then would call your page via www.mydomain.com, and every subdomain via www.mydomain.com/#subPage

Post a Comment for "Creating And Structuring The Index Page"