Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7043843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:20:18+00:00 2026-05-28T02:20:18+00:00

I have a view that I created in my GWT application and I would

  • 0

I have a view that I created in my GWT application and I would like to embed/use one of the Twitter widgets that twitter provides (like this one http://twitter.com/about/resources/widgets/widget_search). They way they have it inserted is with a script that then writes out the appropiate html. I tried various ways to insert it but I was not able to get it to work — we did get it working by putting it in an iFrame but that has presented other problems.

Here is some sample code that twitter provides to insert it:

<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: 'rainbow',
  interval: 30000,
  title: 'It\'s a double rainbow',
  subject: 'Across the sky',
  width: 250,
  height: 300,
  theme: {
    shell: {
      background: '#8ec1da',
      color: '#ffffff'
    },
    tweets: {
      background: '#ffffff',
      color: '#444444',
      links: '#1985b5'
    }
  },
  features: {
    scrollbar: false,
    loop: true,
    live: true,
    behavior: 'default'
  }
}).render().start();
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:20:19+00:00Added an answer on May 28, 2026 at 2:20 am

    So after looking directly at the twitter widget javascript code I saw that an id can be passed in so an existing element could be used. Too bad twitter didn’t really document all of the different options available (at least not on the page I posted above), I may have figured this out earlier.

    Here is a Sample Composite Widget that will insert a twitter widget and work in GWT, I have tested this code in GWT 2.4 and it worked in Firefox 6, Chrome 16 and IE9 (although IE had some weird styling issues in my environment).

    import com.google.gwt.core.client.Callback;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.core.client.JavaScriptObject;
    import com.google.gwt.core.client.ScriptInjector;
    import com.google.gwt.user.client.DOM;
    import com.google.gwt.user.client.ui.Composite;
    import com.google.gwt.user.client.ui.FlowPanel;
    
    public class TwitterWidget extends Composite {
    
        private JavaScriptObject widgetJsObj = null;
        private final FlowPanel twPanel;
        private final boolean destroyOnUnload;
    
        public TwitterWidget() {
            this(true);
        }
    
        public TwitterWidget(boolean destroyOnUnload) {
            this.destroyOnUnload = destroyOnUnload;
            twPanel = new FlowPanel();
            twPanel.getElement().setId(DOM.createUniqueId());
            initWidget(twPanel);
        }
    
        @Override
        protected void onLoad() {
            super.onLoad();
    
            Callback<Void, Exception> callback = new Callback<Void, Exception>() {
    
                @Override
                public void onSuccess(Void result) {
                    if (nativeEnsureTwitterWidgetJsLoadedAndSetToWnd()) {
                        renderAndStart();
                    } else {
                        GWT.log("even though success has been called, the twitter widget js is still not available");
                        // some logic maybe keep checking every second for 1 minute
                    }
                }
    
                @Override
                public void onFailure(Exception reason) {
                    // TODO Auto-generated method stub
                    GWT.log("exception loading the twitter widget javascript", reason);
                }
    
    
            };
    
            boolean isTwitterWidgetAvailable = nativeEnsureTwitterWidgetJsLoadedAndSetToWnd();
            if (isTwitterWidgetAvailable) {
                renderAndStart();
            } else {
                ScriptInjector.fromUrl("http://widgets.twimg.com/j/2/widget.js")
                    .setWindow(ScriptInjector.TOP_WINDOW)
                    .setCallback(callback)
                    .inject();
            }
        }
    
        @Override
        protected void onUnload() {
            super.onUnload();
    
            if (widgetJsObj!=null) {
                // need to manually destroy so that attached events get removed
                if (destroyOnUnload) {
                    nativeDestroyTwitterWidget(widgetJsObj);
                } else {
                    nativeStopTwitterWidget(widgetJsObj);
                }
            }
        }
    
        private native JavaScriptObject nativeRenderStartTwitterWidget(String domId) /*-{
            var twObj = new $wnd.TWTR.Widget({
                version: 2,
                id: domId,
                type: 'search',
                search: 'rainbow',
                interval: 30000,
                title: 'It\'s a double rainbow',
                subject: 'Across the sky',
                width: 250,
                height: 300,
                theme: {
                    shell: {
                      background: '#8ec1da',
                      color: '#ffffff'
                    },
                    tweets: {
                      background: '#ffffff',
                      color: '#444444',
                      links: '#1985b5'
                    }
                },
                features: {
                    scrollbar: false,
                    loop: true,
                    live: true,
                    behavior: 'default'
                }
            }).render().start();
            return twObj;
        }-*/;
    
        private native boolean nativeEnsureTwitterWidgetJsLoadedAndSetToWnd() /*-{
            // this only works when TWTR has been properly loaded to $wnd directly
            if (!(typeof $wnd.TWTR === "undefined") && !(null===$wnd.TWTR)) {
                return true;
            }
            return false;
        }-*/;
    
        private native JavaScriptObject nativeStopTwitterWidget(JavaScriptObject twObj) /*-{
            return twObj.stop();
        }-*/;
    
        private native JavaScriptObject nativeDestroyTwitterWidget(JavaScriptObject twObj) /*-{
            return twObj.destroy();
        }-*/;
    
        private void renderAndStart() {
            widgetJsObj = nativeRenderStartTwitterWidget(twPanel.getElement().getId());
            // you can call other native javascript functions 
            // on twitWidgetJsObj such as stop() and destroy()
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom UIView that I would like to use on multiple
I have a view that was created through the scaffold. One of the fields
I have created a list view that displays the names and dates of items
We have created a new List View Style that shows thumbnails from a picture
if i have created a view model and have a partial form that is
I have an initial table view that I created as the initial menu within
I got a view (GWT MVP pattern) that contains a listbox. I created a
have a view that loads and a serial dispatch queue that is created, loads
I have a user control I have created that contains a details-view that I
I have a view that I created using default buttons and background in Interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.