Google プラスの共有ボタン (+1 ボタンではなく) を非同期的に iframe に読み込むにはどうすればよいですか? +1ボタンでそれを行うことができました。
8801 次
2 に答える
2
ユーザーが何かの上にカーソルを置いたときにボタンを明示的にレンダリングする場合は、次のように明示的なレンダリング フローを使用する必要があります。
https://developers.google.com/+/plugins/+1button/
ただし、共有ボタンを使用しているため、明示的なレンダリング コードを使用して div に直接レンダリングすることはできません。代わりに、共有リンクを作成し、レンダリングを明示的に設定してから、JavaScript を使用して共有ボタンのレンダリングをトリガーできます。
関連するコードは次のとおりです。
<html>
<head>
<title>+Share: Explicit render</title>
<link rel="canonical" href="http://www.example.com" />
<script type="text/javascript">
window.___gcfg = {
lang: 'en-US',
parsetags: 'explicit'
};
function renderShare() {
gapi.plus.go(); // Render all the buttons
}
</script>
</head>
<body>
<a href="#" onClick="renderShare();">Render the share control</a>
<!-- a share button that will get rendered when gapi.plus.go is called -->
<div class="g-plus" data-action="share" id="share-div"></div>
</body>
<script type="text/javascript">
// Asynchronously load the plusone script, for performance
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
</html>
あなたにとって、+1 ボタンをレンダリングするために、ユーザーが明示的にクリックしなければならないボタンとは別のトリガーを使用しようとしていると思います。レンダリングをトリガーしたいものに適切なイベントを使用するだけです。
于 2012-11-26T21:15:40.867 に答える