'. '

Bck2BrwsrBlobURLs

From APIDesign

(Difference between revisions)
Jump to: navigation, search

JaroslavTulach (Talk | contribs)
(New page: For a long time users of Bck2Brwsr complained that loading images, or other resources from the browser is complicated. With great delight I can announce that forthcoming [[Bck2Brws...)
Next diff →

Revision as of 01:09, 30 October 2014

For a long time users of Bck2Brwsr complained that loading images, or other resources from the browser is complicated. With great delight I can announce that forthcoming version 0.12 contains solution. It is build around JavaScript Blob support. In case you have an application class with an image resource next to it, you can:

public static void onPageLoad() throws Exception {
    URL u = Main.class.getResource("launcher.png");
 
    // by opening the connection one requests creation of Blob
    URLConnection conn = u.openConnection();
    // the conn.getURL() may actually differ from u
 
    changeImg(conn.getURL().toExternalForm());
}
 
@JavaScriptBody(args = "url", body = "document.getElementById('img').src = url")
private static native void changeImg(String url);

The conn object in Bck2Brwsr also implements Closeable, so when the URL is no longer needed, it can be freed from browser by calling close().

The above code works in Bck2Brwsr as well as in FXBrwsr. The created connection

Personal tools
buy