duanheye7909 2015-02-25 16:42
浏览 283
已采纳

history.pushState删除部分网址

I'm trying to implement history.pushState into our website to replace hash bangs but I'm puzzled as to why every time I click on a link that instead of appending the href value onto the current url e.g. www.abc.com/123.php/20 it instead makes it www.abc.com/20 even though I am still on the 123.php page (hopefully that makes sense).

I should also point out the the html below is created via php.

I have read quite a few tutorials explaining how to implement this and read a lot of articles, but still no luck. Also all the tutorials I have found show this working with the main menu but this is working with a grid of projects that load in data with Ajax.

Any help would be hugely appreciated!

<a id="projectAnchor" class="projectItem powerline" href="30" style="position: absolute; left: 5px; top: 5px;">
    <div id="imgContainer" name="Western Power Distribution - Brechfa Connection" href="#!30">
        <img id="projectImg" src="projectContent/30/198-th.jpeg" alt="Western Power Distribution - Brechfa Connection">
    </div>
    <img id="projectIcon" src="images/solution/powerlineIconB.png" alt="Powerline">               
        <p id="projectText">Western Power Distribution - Brechfa Connection</p>
        <div class="blueBar" id="colourBar"> </div>
</a>

var e, p;
$(function(){
    p = $(".projectItem").click(function() {
        e = $(this);
        if(!e.hasClass('active')){
            getResults();
            history.pushState(null, null, e.attr('href'));
        }
        return false;
    });
});

window.addEventListener("popstate", function(){
    e = $('a[href="'+location.pathname.split("/").pop()+'"]');
    getResults();
});

function getResults(){
    p.removeClass('active');
    e.addClass('active');
    $.get('projectT.php', {id: e.attr('href')}, function(data){
        $('#projectContent').html(data);
    });
}

</div>
  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 bulk-RNAseq数据下游分析(从TPM/vst开始)
      • ¥200 把公众号页面和文章,嵌入到其他平台!就像搬家一样!
      • ¥20 matlab编程问题。详情如下,我也用chatgpt了,但是效果不好。本人没啥编程基础
      • ¥15 matlab画三维流场
      • ¥100 IIC通讯数据算法分析
      • ¥15 matlab 绘制涡流场
      • ¥15 依存句法分析如何与BERT模型及GCN相结合
      • ¥66 有偿收一个会Python 与unitysocket通信,会简单mediapipe手势识别的哥
      • ¥15 药店卖药设计使利润最大
      • ¥15 模拟银行实现VIP服务