weixin_33712881 2014-01-14 08:43 采纳率: 0%
浏览 13

Ajax / jQuery位置

i want to add some hash ref linking that when i click on a menu button it changed to the actual section maybe from

http://www.mycompany.com/about to http://www.mycompany.com/work or maybe /something

i have this solution but i don't know how can i add this to my actually solution.

$(document).ready(function(){
     $('#allcontent').load('data/home.html');

    $('.hovers').click(function() {
       var page = $(this).attr('href'); 
    $('#allcontent').load('data/' + page + '.html');
    return false;
});
});

Here is my Fiddle: DEMO

Maybe with this? window.location.hash =

Thank you so much

  • 写回答

1条回答 默认 最新

  • weixin_33725515 2014-01-14 09:06
    关注

    What I think you are looking for is to load the page content through ajax and still be able to update the url to /something

    http://www.mycompany.com/about to http://www.mycompany.com/work or maybe /something

    To achieve this, you just need to load the content of the page you want and change the location url to the desired page name by doing something like,

    <script type="text/javascript">
     function processAjaxData(response, urlPath){
      document.getElementById("content").innerHTML = response.html;
      document.title = response.pageTitle;
      window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
     }
    </script>
    

    REF: Modify the URL without reloading the page

    A website which has actually implemented this. What they are doing is, loading the page contents on clicking on menu items through ajax. And then setting the browser url through js. They have even kept the menu links to /pages instead of #values as this boosts seo.

    评论

报告相同问题?

悬赏问题

  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据