1

我有包含标题、css 等的secure.php 页面。在安全页面中,我有一个名为动态的div,其他php 页面的内容被加载到其中。

具有该内容的页面是 page1.php 和 page2.php。

我简化的安全 php 代码:

<!DOCTYPE html>
<head>    
    <script src="js/jquery-1.10.0.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script src="js/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    <script src="js/jquery.ba-hashchange.min.js"></script>
    <script>

    $(document).ready(function() {
        loadPage1();
    });
    $(function() {
  $(window).hashchange( function() {

    if (location.hash == "#page1") {
        loadPage1();
    };
    if (location.hash == "#page2") {
        loadPage2();
    };
  })

  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).hashchange();

});


    function loadPage1() {
        $('#dynamic').load('page1.php');
    }

    function loadPage2() {
        $('#dynamic').load('page2.php');
    }

</script>

    </head>
    <body class="bodysecure">        
        <div id="headermenu">
            <div class="menuitem"><a href="#page1" onmouseover="" onClick="loadPage1()">Page1</a></div>
            <div class="menuitem"><a href="#page2" onmouseover="" onClick="loadPage2()">Page2</a></div>
        </div>

            <div id="dynamic"></div>

    </body>
</html>

我当前的代码运行良好。也许它可以更好地编程,但这不是这里的问题。

问题是,后退/前进按钮不起作用,您无法为特定页面添加书签,因为 URL 始终是 secure.php。我去寻找一个解决方案,看到许多非常复杂的插件(我只是一个初学者)。

没有插件有没有简单的方法来做到这一点?喜欢使用标签?谁能给我一个例子,也许是在小提琴上?

4

1 回答 1

1

您可以执行以下操作:

// Document ready checks if the hash is set in which it loads the correct page.
// on default (if no hash set) page1.php will be the page.
$(document).ready(function() {
    var page = window.location.hash || 'page1.php'; 
    loadPage(page);
});

// This loads the actual page.
function loadPage(page) {
    $('#dynamic').load(page);
    window.location.hash = page;
}
于 2013-08-10T19:54:15.877 回答