Zhaidarbek
Zhaidarbek

Reputation: 310

Can't add external script into gwt widget

I am trying to add google gadget into FlowPanel(or HTMLPanel), but after a host page is loaded it navigates away from my page and shows gadget in a new page, if i click browser's back button it loads host page and again navigates away to new page to show the gadget.

Here is the code:

String code="here_goes_scrip_tag_for_gadget";
flowPanel.add(new HTML(SafeHtmlUtils.fromTrustedString(code)));

What am i doing wrong, please help.

UPDATE The above code to load script was wrong, i've modified it as following:

        FlowPanel gadgetContainer = new FlowPanel();
        Element script = Document.get().createScriptElement();
        script.setAttribute("type", "text/javascript");
        script.setAttribute("src", "http://www.gmodules.com/ig/ifr?url=http://digg.com/goog/ig.xml&up_user=&up_thumbnail=1&up_filter=0&up_num=5&up_type=popular&up_refresh=0&up_tab=0&up_offset=0&up_pagination=0&up_business=true&up_entertainment=true&up_gaming=true&up_lifestyle=true&up_offbeat=true&up_politics=true&up_science=true&up_sports=true&up_technology=true&up_world_news=true&synd=open&w=320&h=200&title=Digg&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js");
        gadgetContainer.getElement().appendChild(script);

But it still doesn't work.

Upvotes: 0

Views: 433

Answers (1)

Colin Alworth
Colin Alworth

Reputation: 18331

For solving this problem in general, check out the com.google.gwt.core.client.ScriptInjector class - it has two methods that allow you to inject scripts into the page in a cross browser way. The way you are attempting to inject the script content won't work cross browser.

Looking specifically at your gadget case, I'm guessing that the script you are loading has code in it to prevent it from being loaded into another page. Have you tried to use a plain html page that references that script tag? If the same thing happens, see if you can see where in the script file the page reassigns window.location.

Upvotes: 1

Related Questions