简体   繁体   English

PHP Include更改DIV内容,但在刷新时保留内容

[英]PHP Include to change DIV contents but hold contents on refresh

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. 我正在为Uni模块创建一个非常基本的站点,并且当前有一个简单的onClick Javascript用于更改主要内容DIV的内容。 The simple script is calling a PHP Include file to fill the DIV. 简单的脚本是调用PHP Include文件来填充DIV。

HTML 的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. 我有一个无法解决的问题是,当我刷新页面时(无论页面处于打开状态),站点都会返回到home.php文件。 I understand that this is going to happen because I am calling the home.php file in the index.html file. 我知道这会发生,因为我正在index.html文件中调用home.php文件。

My question is how can I hold the current php file during a refresh? 我的问题是如何在刷新期间保存当前的php文件?

I was thinking of using localStorage to hold the link being use but my attempts didnt work. 我当时在考虑使用localStorage来保存正在使用的链接,但是我的尝试没有用。 Could someone please give me a little guidance on this please. 有人可以给我一些指导。

Cheers in advance, 提前加油

Blinky 眨眼

Instead of a cookie or localStorage, how about changing the hash? 代替cookie或localStorage,如何更改哈希?

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM