Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How can I set an ID to an iframe in a HtmlPane?

    Hi! I am Javier from Spain and I need some help ;).

    I am tried to set an ID to an iframe created with an HtmlPane in SmartGwt 2.0.6.

    Code:
    			mapLayout = new VLayout();
    			
    			mHtmlPane = new HTMLFlow();  
    			mHtmlPane.setShowEdges(true);
    			
    			mHtmlPane.setContentsURL("map.html");
    			mHtmlPane.setID("miMapa");
    			mHtmlPane.setContentsType(ContentsType.PAGE);
    						
    	                mapLayout.addMember(mHtmlPane);
    The reason because I want to set an id to the iframe is that I want to call the JavaScript functions in the map.html.

    Debuggin with Chrome I can see randoms IDs but with Firefox there is no any ID.

    Code:
    public static native void goToTracking() /*-{	  
    	  $wnd.document.getElementById("miMapa").contentWindow.alerta();
    	}-*/;
    Because I can not set the ID I always recibe the same error when I try to call JavaScript:

    Code:
    com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot read property 'contentWindow' of null
    	    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
    	    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    	    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    	    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    	    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    	    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    	    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    	    at sun.reflect.GeneratedMethodAccessor123.invoke(Unknown Source)
    	    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	    at java.lang.reflect.Method.invoke(Unknown Source)
    	    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    	    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    	    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    	    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    	    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    	    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    	    at java.lang.Thread.run(Unknown Source
    Best regards!
    Thanks!

    #2
    Problem solved. I found two solutions:

    This one on this forum in other thread:
    Code:
    mHtmlPane.setContents( "<iframe id='" + "miMapa" + "' src='" + "map.html" + "' />" );
    And this other more... professional hehe ;):
    Code:
                htmlPane.getElement().setId("miMapa"); 
                htmlPane.getElement().setPropertyString("name", "miMapa"); 
                htmlPane.getElement().setPropertyString("id", "miMapa");
    Both with the same JSNI call:

    Code:
    public static native void alerta() /*-{ 
          //$wnd.document.getElementById("miMapa").contentWindow.alerta(); 
          $wnd.document.getElementById("miMapa").contentWindow.alerta(); 
        }-*/;
    After this I have other problem with firefox and iexplrer with the height of the frame. To solve this I use this style in the main html page:

    Code:
    <style type="text/css">
       html, body, div, iframe { margin:0; padding:0; height:100%; }
       iframe { display:block; width:100%; border:none; }
      </style>

    Comment

    Working...
    X