Multiple distinct pages in one HTML file

后端 未结 12 1001
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 10:05

Is there any way to have multiple distinct HTML pages contained within a single HTML file? For example, suppose I have a website with two pages:

Page 1 : cl         


        
12条回答
  •  时光取名叫无心
    2020-12-04 10:43

    have all the pages in distinct div areas

    First Page Contents

    then use a js script to workout what you are viewing (like within an hashtag style) to navigate. Either that, or ajax to get the response from a specific file (like /pages/page1.html)

    var $prehashval = "";
    function loop()
    {
        if (location.hash.slice(1)!=$prehashval)
            hashChanged();
    
        $prehashval = location.hash.slice(1);
        setTimeout("loop()", 100);
    }
    function hashChanged()
    {
        var $output;
        switch (location.hash.slice(1))
        {
            case "page1":
                document.getElementById('page1').style.display = "";
                document.getElementById('page2').style.display = "none";
                break;
            case "page2":
                document.getElementById('page1').style.display = "none";
                document.getElementById('page2').style.display = "";
                break;
            default:
                $output = location.hash.slice(1);
        }
    }
    loop();
    

提交回复
热议问题