像网站加载一样

use*_*068 3 jquery

如何在不重新加载窗口的情况下使页面加载像rapidshare

例如:

https://rapidshare.com/#!home

如果您浏览页面,浏览器窗口没有重新加载,它只是更改URL的最后一个参数,如#!myrs_overview,#!buyrapids,#!help等

当我在firebug中看到它时,它给出了参数名称,即从上面(home,buyrapids) http://screensnapr.com/v/wPJtCY.png

谢谢

Ali*_*guy 5

#!被称为hashbang,它是允许Google抓取ajax页面标准.他们只是使用AJAX重新填充页面信息,然后更新哈希URL:

采用以下示例导航链接:

<a href="contact.php" title="Contact Us" id="contact-us">Contact</a>
Run Code Online (Sandbox Code Playgroud)

如果我们不希望页面重定向contact.php但我们想要加载内容,我们可以这样做:

<a href="#!contact" class="nav-link" rel="contact.php" title="Contact Us" id="contact-us">Contact</a>
Run Code Online (Sandbox Code Playgroud)

然后使用JQuery:

$('.nav-link').click(function(){
    var $this = $(this);
    $.ajax({
        url: $this.attr('rel'),
        success: function(data){
            $('body').fadeOut().html(data).fadeIn();
        }
    });
});  
Run Code Online (Sandbox Code Playgroud)

如果有人使用网址中的hashbang进入您的网站,我们只需检测它并加载相应的网页; 像这样的东西会起作用:

$(function(){
    if(window.location.hash){
        if(window.location.hash.indexOf('#!') === 0){
            $.ajax({
                url: window.location.hash.replace('#!','') + '.php',
                success: function(data){
                    $('body').fadeOut().html(data).fadeIn();
                }
            });
        }
    }
});
Run Code Online (Sandbox Code Playgroud)