简体   繁体   English

更改G +网址参数而不刷新页面

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

I have a link that a user can share on fb and G+ . 我有一个链接,用户可以在fbG+上共享。

The user can modify that link and he did it with an ajax call so the page is not refreshing. 用户可以修改该链接,并使用ajax调用来完成该链接,因此页面不会刷新。

My gplus button code : 我的gplus按钮代码:

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

when the user changes the url I update the href attribute too : 当用户更改url时,我也更新了href属性:

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

The problem is that the G+ button still load the old url. 问题在于, G+按钮仍会加载旧的网址。 But only by refreshing I get the new one. 但是只有刷新,我才能得到新的。

My question is how can i change the G+ url without refreshing the page ? 我的问题是如何在不刷新页面的情况下更改G+网址?

Is this what you want (obviously changing that prompt for your ajax callback logic)? 这是您想要的吗(显然更改了您的Ajax回调逻辑的提示)?

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

HTML HTML

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

JS 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);

});

Be aware that I'm loading the plusone.js in the external resources of that jsfiddle. 请注意,我正在将plusone.js加载到该jsfiddle的外部资源中。

BTW, why did you use the Symfony2 tag? 顺便说一句,为什么要使用Symfony2标签?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM