Skip to content

Instantly share code, notes, and snippets.

@branflake2267
Created February 12, 2020 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save branflake2267/d5cd1f67e6f7e2ae43c5043659c9771b to your computer and use it in GitHub Desktop.
Save branflake2267/d5cd1f67e6f7e2ae43c5043659c9771b to your computer and use it in GitHub Desktop.
GXT remove iframe
package com.sencha.gxt.test.client._northgate;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.dom.client.NodeList;
public class IframeReferenceSandbox implements EntryPoint {
protected static class IFrameElementExt extends IFrameElement {
protected IFrameElementExt() {
}
public final native JavaScriptObject getWindow() /*-{
return this.contentWindow;
}-*/;
public final native void clear() /*-{
this.src = '';
// this.contentWindow.document.write('');
// this.contentWindow.close();
}-*/;
}
@Override
public void onModuleLoad() {
NodeList<Element> iframes = Document.get().getElementsByTagName("iframe");
if (iframes != null) {
for (int i=0; i < iframes.getLength(); i++) {
GWT.log("iframe " + i);
// option 1
// IFrameElement iframe = iframes.getItem(i).cast();
// iframe.setSrc("about:blank");
//
// Document document = iframe.getContentDocument();
// document.removeAllChildren();
//
// Document.get().removeChild(iframe);
// option 2
IFrameElementExt iframe2 = iframes.getItem(i).cast();
iframe2.clear();
iframe2.removeFromParent();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment