0

I am creating a very basic site for a Uni module and currently have a simple onClick Javascript being used to change the contents of the main content DIV. The simple script is calling a PHP Include file to fill the DIV.

HTML

<div id="content" class="colorPicker1">
<!--Populate content div on load-->
<?php include 'php/home.php' ?>
</div>

<a href="winInstall.html" onClick="$('#content').load('php/winInstall.php'); return false;" title="Windows only installation">Windows 7/8</a>

The problem I have and am not able to figure out is when I refresh the page, which ever it is on, the site returns to the home.php file. I understand that this is going to happen because I am calling the home.php file in the index.html file.

My question is how can I hold the current php file during a refresh?

I was thinking of using localStorage to hold the link being use but my attempts didnt work. Could someone please give me a little guidance on this please.

Cheers in advance,

Blinky

Blinkydamo
  • 1,582
  • 9
  • 20
  • [`history.pushState()`](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history) coupled with a content-loading script reading the URL (like jQuery UI Tabs) would work. See [history.js](https://github.com/browserstate/history.js/) too. – Jared Farrish Mar 20 '14 at 22:54
  • http://stackoverflow.com/a/15745625/451969 – Jared Farrish Mar 20 '14 at 22:58

1 Answers1

0

Instead of a cookie or localStorage, how about changing the hash?

<a href="winInstall.html" class="ajax-link" title="Windows only installation">Windows 7/8</a>
<script>
(function ($) {
    var load_page = function (path) {
        location.hash = '#'+path;
        $('#content').load('php/'+path.replace('.html', '.php'));
    };

    $('.ajax-link').click(function (v) {
        v.preventDefault();
        load_page($(this).attr('href'));
    });

    if (location.hash && location.hash != '#') {
        load_page(location.hash.substr(1));
    }
})(jQuery);
</script>
M Miller
  • 5,364
  • 9
  • 43
  • 65
  • Cheers for the answer, however, i am trying this suggestion and it seems to just place "#php/winInstall.php" onto the end of the index.html in the address bar. It doesn't change the page. – Blinkydamo Mar 20 '14 at 23:36
  • If the hash is changing, it means `load_page` is being called, so there's an issue with the `.load` part. Open the console and check for errors. Also, try `console.log('php/'+path.replace('.html', '.php'));` to make sure that is the correct path relative to your page and a file exists there. – M Miller Mar 21 '14 at 00:16