簡體   English   中英

更改G +網址參數而不刷新頁面

[英]Changing G+ url parameter without refreshing the page

我有一個鏈接,用戶可以在fbG+上共享。

用戶可以修改該鏈接,並使用ajax調用來完成該鏈接,因此頁面不會刷新。

我的gplus按鈕代碼:

<link rel="canonical" href="{{ url }}" />
<g:plus action="share" style="height: 28px;" ></g:plus>

當用戶更改url時,我也更新了href屬性:

$.post(url,{
       someParams:"someValues"
   },function(data){
 .
 .
 .
 // updating the href attribute with the new modified url 
 $('link[rel="canonical"]').attr("href",data.url);
 }

問題在於, G+按鈕仍會加載舊的網址。 但是只有刷新,我才能得到新的。

我的問題是如何在不刷新頁面的情況下更改G+網址?

這是您想要的嗎(顯然更改了您的Ajax回調邏輯的提示)?

http://jsfiddle.net/coma/2783J/6/

HTML

<!-- Place this tag where you want the +1 button to render. -->
<div id="gplus"></div>
<button>change it!</button>

JS

$(function() {

    var container = $('#gplus');
    var render = function(url) {

        container.html('<g:plusone href="' + url + '"></g:plusone>');
        gapi.plusone.go('gplus');

    };

    $('button').click(function(event){

        var url = prompt('Give me an URL');
        render(url);

    });

    render(location.href);

});

請注意,我正在將plusone.js加載到該jsfiddle的外部資源中。

順便說一句,為什么要使用Symfony2標簽?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM