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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀