2

GWT アプリケーションに Google-Plus を埋め込もうとしています。Horizo​​ntalPanel に埋め込みたいと思います。+1button 開発者の googleを読みました。この特定の問題に関する投稿は、stackoverflow で見つかりませんでした。私の問題は、js を GUI コンポーネントに含める方法がわからないことかもしれません。Google+ コードをパネルに追加する方法の例をいただければ幸いです。

4

3 に答える 3

5

方法は次のとおりです。

ドキュメンテーション:

 <!-- Place this tag in your head or just before your close body tag -->
 <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
 <!-- Place this tag where you want the +1 button to render -->
 <g:plusone></g:plusone>

GWT で:

private void drawPlusOne() {
    String s = "<g:plusone href=\"http://urltoplusone.com\"></g:plusone>";
    HTML h = new HTML(s);
    somePanel.add(h);

    // You can insert a script tag this way or via your .gwt.xml
    Document doc = Document.get();
    ScriptElement script = doc.createScriptElement();
    script.setSrc("https://apis.google.com/js/plusone.js");
    script.setType("text/javascript");
    script.setLang("javascript");
    doc.getBody().appendChild(script);
  }
于 2012-08-30T05:16:21.260 に答える
0

私は個人的に GWT に +1 ボタンを埋め込んだことはありませんが、リンクされた記事を見れば一目瞭然です。

「シンプルなボタン」セクションでは、GooglePlus 統合を実装する最も簡単な方法はこれを追加することであると示しています。

<script src="https://apis.google.com/js/plusone.js" />
<g:plusone></g:plusone>

まず、<script>タグをファイルに含める必要があり.gwt.xmlます。

<g:plusone></g:plusone>次に、次のように実装します。

public class GPlusOne extends SimplePanel {
    public GPlusOne () {
        super((Element)Document.get().createElement("g:plusone").cast());
    }
}

(このコードはテストされていませんが、aSimplePanelを拡張して任意の HTML 要素としてコンパイルできるという単純な概念に基づいていることに注意してください。)

GPlusOne次に、ボタンを表示したい場所で新しい要素を使用します。

于 2012-08-29T17:28:26.063 に答える