On Tuesday, May 14, 2013 1:37:21 PM UTC+2, Mohammad Al-Quraian wrote:
>
> Basically, I want to use something like this:
> https://twitter.com/about/resources/buttons#tweet
>
> I found this page which suggests loading the script at the beginning, then 
> using jquery to look for certain elements and then renders relevant 
> elements:
>
> http://thegregstier.blogspot.com/2011/05/facebook-and-twitter-buttons-in.html
>
> I also found this code:
>
> .........
> final String scriptStr = "!function(d,s,id){" + " var 
> js,fjs=d.getElementsByTagName(s)[0];"
>                                  + " if(!d.getElementById(id)){" + 
> "js=d.createElement(s);"
>                                  + " js.id=id;js.src='//
> platform.twitter.com/widgets.js';"
>                                  + " fjs.parentNode.insertBefore(js,fjs);"
>                                  + " }}(document,'script','twitter-wjs');"
> ;
>
>     final ScriptElement scriptElement = Document.get().createScriptElement
> (scriptStr);
>
>     // we place the script just after the body tag
>     bodyElement.appendChild(scriptElement);
> Any suggestions? I want something simple and clean. Thanks.


FYI, the code above can be simplified a bit using ScriptInjector:

```
ScriptInjector.fromString(/* the script given by Twitter */)
    .setWindow(ScriptInjector.TOP_WINDOW)
    .inject()
```

And make sure you insert the Anchor in the DOM before injecting the script.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to