Re: How get iFrame contents with different domains ?

73 views
Skip to first unread message

gpike

unread,
Sep 25, 2012, 12:26:52 PM9/25/12
to google-we...@googlegroups.com
Hi,

  You can't directly in GWT it honors cross site scripting you can however drop down to Javascript. Write a JSNI method that accesses the containing docs parent (your app) by accessing top, then in your code you can access the iFrame and then it's document. Something like this:

public static DocumentElement getFrameDocumtent() {
FrameElement top = getTopDocument().getElementById("MyiFrame");
return top.getContentDocument();
}

public static native Document getTopDocument() /*-{
return top.document;
}-*/;

I haven't tested this code but pulled pieces from some of my working code to give you an idea.

Hope that helps,

Gordon Pike

On Friday, September 21, 2012 2:28:25 AM UTC-6, Coco Gwt wrote:
Hi,

i have created an iFrame in my project that calls an external service (for example whatismyip.com) that returns my public IP.
the problem is i cant get iFrame content, because there is a completly different domains.
the question is how can i get this iFrame contents ? its very urgent please !

Thank you
Message has been deleted

gpike

unread,
Sep 25, 2012, 1:25:54 PM9/25/12
to google-we...@googlegroups.com
After sending this I realized I sent it too early. The code below only works after you get both documents under the same domain because of cross-site scripting protection in the browser. To bring them both under the same domain you can either setup Apache or Nginx as reverse-proxy or write a servlet deployed with your GWT server side code that proxies requests to the other domain. If you just have a couple of pages to proxy I would do the servlet approach. I've done both methods. There are a couple of example proxy servlets you could start with and deploy one of them in your web.xml.

Thanks,

Gordon Pike

Кирилл Карпенко

unread,
Sep 25, 2012, 1:35:04 PM9/25/12
to google-we...@googlegroups.com

You cannot do this the way you want. It is simply does not allowed by the most of browsers.

There is only possible way you can to choose is to build extension which browser grant extended permissions set. But user must setup it explicitly.

25.09.2012 18:58 пользователь "Nabil" <chane...@gmail.com> написал:
Hi,

i have created an iFrame in my project that calls an external service (for example whatismyip.com) that returns my public IP.
the problem is i cant get iFrame content, because there is a completly different domains.
the question is how can i get this iFrame contents ? its very urgent please !

Thank you

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/_HHds9xI1ToJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Reply all
Reply to author
Forward
0 new messages