【问题标题】:Google+ Button not appearingGoogle+ 按钮未出现
【发布时间】:2011-10-05 11:26:12
【问题描述】:

以下是代码:-

    <script type="text/javascript">

var timer = 150;
var currentWindow;
$(document).ready(function() 
{
    $("#creditme").button({
        icons: { primary: "ui-icon-check" }
    }).hide();
    $("#viewad").button({
        icons: { primary: "ui-icon-play" }
    }).hide();
    $("#progressbar").progressbar({value: 0}).hide();

    var time;
    var id;
    var title;
    var url;

    $('.googlep-advertisement').bind('click', function()
    {       
        id = $(this).attr('id');
        title = $(this).text();
        url = $('#yturl-'+id).text();
        timer = $('#ytime-'+id).text();
        $("#dialog-message").dialog({
            modal: true,
            width: 700,
            title: title,
            resizable: false,
            draggable: false,
            beforeClose: function() { clearAd(); }
        });
        if (!$("#progressbar").is(":visible") && !$("#creditme").is(":visible")) 
        {
            $("#viewad").show();
        }
    });


    $("#viewad").bind('click',function() {
       $.get("googlep_credit.php" + '?start=' + id);
       $("#viewad").hide();
       $("#progressbar").progressbar('value', 0).show();
       currentWindow = window.open(url, 'videoad', 'height=480,width=640', false);
       window.blur();
       window.focus();
       progresscount(timer);
    });
    $("#creditme").click(function() {
        $.get("googlep_credit.php" + '?id=' + id);
        $("#creditme").hide();
        $("#dialog-message").dialog('close');
        $("#"+id).parent().parent('tr').fadeOut('slow');
    });
    function progresscount(time) 
{
    if(time == 0) 
    {
        if(isWindowClosed() == true)
        {
            alert('You closed the popup before timer reached zero or you are using popup-blocking software.');  
            $("#dialog-message").dialog('close');
        }
        else
        {
            $("#creditme").html('<g:plusone callback="plusone_vote" href="'+url'"></g:plusone>');
            $("#creditme").show();
        }   
        $("#progressbar").hide();
    } 
    else 
    {
        time--;
        $("#progressbar").progressbar('value', parseInt((timer - time) * 100 / timer));
        setTimeout(function() { progresscount(time) }, 100);
    }
}
});

function isWindowClosed()
{
    if (!currentWindow || typeof currentWindow == 'undefined' || currentWindow && currentWindow.closed) 
    {
        return true;
    }
    else
    {
        return false;
    }
}



function clearAd()
{

}
</script>
<style>
.dialog-message {

}
</style>

<div id="dialog-message" class="dialog-message" title="View Video" style="display:none">
    <p>

        <center>
            <button id="viewad" style="ui-helper-hidden">Click here to view the video</button>
            <div id="progressbar"></div>
            <button id="creditme" style="ui-helper-hidden">Test</button>
        </center>
    </p>
</div>

代码没有问题。 问题是:- http://dl.dropbox.com/u/14384295/70.jpeg

当使用谷歌浏览器检查元素检查时, 代码显示为 http://dl.dropbox.com/u/14384295/71.jpeg

正常工作将显示为 > http://dl.dropbox.com/u/14384295/72.jpeg

该部分中的 google js 似乎没有转换代码。如果让我感到困惑,我很抱歉。

我可能错误地添加了“url”变量

【问题讨论】:

  • 同一张图片粘贴了 3 次,仅供参考。
  • 只是想让你知道:D

标签: php jquery jquery-ui google-plus


【解决方案1】:

我很确定您的问题出在这一行:

$("#creditme").html('<g:plusone callback="plusone_vote"></g:plusone>');

您在运行 Google +1 脚本后动态添加 &lt;g:plusone&gt; 元素,因此没有任何反应。

要解决它,只需将 +1 标记从头开始放在 html 中,以便 +1 脚本可以找到并呈现它,并且仅在需要显示时调用 $("#creditme").show();

<button id="creditme" style="ui-helper-hidden">
    <g:plusone callback="plusone_vote"></g:plusone>
</button>

如果您想在页面加载后动态更改 URL,check out the examples from the Google documentation。它将允许您显式加载按钮。

【讨论】:

  • 仍然不起作用..我会动态添加“url”变量。
  • 我假设您包含 +1 脚本? &lt;script type="text/javascript" src="https://apis.google.com/js/plusone.js"&gt;&lt;/script&gt;。如果你是,什么实际上不起作用?不显示吗?
  • 对不起,我的意思是这样它会起作用,而且确实起作用。是的,我包括 +1 脚本 >
猜你喜欢
  • 1970-01-01
  • 2018-06-11
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
  • 1970-01-01
  • 1970-01-01
  • 2019-07-10
  • 1970-01-01
相关资源
最近更新 更多