-2

我知道通过 PHP 超级变量这是不可能的,但请参阅这个网站:

When we navigate on the pages, the title and meta just changes and this affect the facebook too, see:

How he is doing it? I have a ajax navigation system too, and need to set og, but I don't know how to do dinamically as he did.

Just a comment, he have hidden INPUTS with values of the meta:

But I still don't know how he can parse this before the website being rendered.

4

2 回答 2

0

URL 片段永远不会发送到服务器。它被浏览器用作参考。“传统上”它用于滚动到具有片段引用的 ID 的元素,但最近它被赋予了一些更奇特的用途。

特别#!是一个shebang,意思是“这个页面正在被AJAX加载,但是如果你加载以下相对于域的内容,你无论如何都会得到整个页面”——这对搜索引擎特别有用。

基本上,结合使用 AJAXlocation.hash来使其工作。

于 2013-06-12T22:45:27.810 回答
0

这只是一些 js(jQuery)

<script type="text/javascript">
    var current_page = '';
    $("a").live("click", function(){
        return change_hash(this,1);
    });
    function change_hash(el,type) {
        if(type==1) {
            var link = $(el).attr("href");
        }
        else
        {
            var link = el;
        }
        var link_ar = link.split('/#!');
        if(link_ar[1]!=undefined) {
            if((link_ar[1].length>3)&&(link_ar[1].substr(0,1)=='/')) {
                window.location.hash = '#!'+link_ar[1];
                return false;
            }
            else
            {
                return true;
            }
        }
        else
        {
            return true;
        }
        return false;
    }
    $(function(){
        $(window).hashchange( function(){
            address = location.hash.replace("#!","");
            var skip=false;
            if((address.substr(0,1)=='/')&&(address!=current_page)) {
                $("#content").html('<div class="content-box"><div class="ajax-loading">carregando...</div></div>');
                $("html, body").animate({ scrollTop: 0 }, "slow");
                if (address.indexOf(".php") == -1) {
                    var newaddress = address.replace(/[^a-zA-Z0-9_\.]+/g,"");
                    if('/'+newaddress!=address) { change_hash('/#!/'+newaddress,2);skip=true; }
                    address='/PerfilDetalhe.php?user='+newaddress;
                }
                if(skip==false) {
                    $.get('http://www.suamusica.com.br'+address,    function(htmldata) {
                        $("#content").html(htmldata); 
                        document.title = $('#metaTitle').val();
                        $('meta[name=description]').attr('content', $('#metaDescr').val());
                        $('meta[name=keywords]').attr('content', $('#metaKeywords').val());
                        $('meta[property="og\\:description"]').attr('content', $('#metaDescr').val());
                        $('meta[property=og\\:title]').attr('content', $('#metaTitle').val());
                        $('meta[property=og\\:url]').attr('content', $('#metaURL').val());
                        $('meta[property=og\\:image]').attr('content', $('#metaImage').val());
                        $('meta[property=og\\:type]').attr('content', $('#metaType').val());
                        $('meta[name=DC\\.title]').attr('content', $('#metaTitle').val());
                        $('meta[name=DC\\.description]').attr('content', $('#metaDescr').val());
                        $('meta[name=DC\\.subject]').attr('content', $('#metaKeywords').val());
                    }).fail(function() { $("#content").html('<div class="content-box error-box"><h1>Ooops!</h1><p>A página acessada não existe ou não foi encontrada.</p></div>'); });
                    current_page = address;
                }
                $.get('http://www.suamusica.com.br/msg_check.php',  function(resp) {
                    if(resp==1) {
                        $('#msg-notify').show();
                    }
                    else $('#msg-notify').hide();
                })

                 $('.tipsy-s').remove();
            }
        });
        var loc_h_n = window.location.hash.replace("#", "").replace("!", "").replace(".do", ".php")
        if(window.location.hash!='#!'+loc_h_n&&window.location.hash!='') {
            window.location.hash = '#!'+loc_h_n;
        }
        $(window).hashchange();
    });
</script>

如您所见,他在点击时返回 false 并根据主题标签值采取行动

于 2013-06-12T22:45:47.067 回答