PDA

View Full Version : Get Dom from iFrame



victor.martinez
28 Oct 2008, 2:06 AM
Hello,

It's posible to interact with a DOM of a iframe ?


ContentPanel cp = new ContentPanel();
cp.setUrl("test.hmtl");

Text html, is a simple html with a text area :


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
</head>
<body>
<textarea id="code" cols="20000" rows="20000">
</textarea>
</body>
</html>


Its posible to acces to the iframe and get/set the content of textarea trougth ext gwt ?

Thanks

skanberg
28 Oct 2008, 2:40 AM
The setUrl method returns a com.google.gwt.user.client.ui.Frame object. And if you use the getElement method you will probably get a com.google.gwt.dom.client.FrameElement object and that class has a getContentDocument method which returns a com.google.gwt.dom.client.Document object which you can use to find your textarea for example using the id.

victor.martinez
28 Oct 2008, 2:56 AM
Not posible..., there some problems with i-frame. I also try to debug looking iinside the object, and only references appear.



ContentPanel cp = new ContentPanel();
com.google.gwt.user.client.ui.Frame object = cp1.setUrl("test.html");
om.google.gwt.user.client.Element ele = object.getElement();
String innerHtml = ele.getInnerHTML();
System.out.println(innerHtml);


Where the value of innerHtml is empty .

skanberg
28 Oct 2008, 3:38 AM
Try something like this:



ContentPanel cp = new ContentPanel();
com.google.gwt.user.client.ui.Frame object = cp1.setUrl("test.html");
com.google.gwt.dom.client.FrameElement frameElement = (com.google.gwt.dom.client.FrameElement) object.getElement();
com.google.gwt.dom.client.Document document = frameElement.getContentDocument();
com.google.gwt.dom.client.TextAreaElement textArea = (com.google.gwt.dom.client.TextAreaElement) document.getElementById("id");
System.out.println(textArea.getValue());

victor.martinez
28 Oct 2008, 3:46 AM
Its not posible to cast Element to FrameElement

skanberg
28 Oct 2008, 11:13 PM
Here is the way to access the iframe:



IFrameElement frame = IFrameElement.as(object.getElement());