←Older revision | Revision as of 01:16, 30 October 2014 | ||
Line 6: | Line 6: | ||
public static void onPageLoad() throws Exception { | public static void onPageLoad() throws Exception { | ||
URL u = Main.class.getResource("yourimg.png"); | URL u = Main.class.getResource("yourimg.png"); | ||
+ | // one can use u.openStream() to do 'lightweight' read from Java code | ||
- | // by opening the connection one requests creation of Blob | + | // by opening the connection one requests creation of browser Blob |
URLConnection conn = u.openConnection(); | URLConnection conn = u.openConnection(); | ||
- | // the conn.getURL() | + | // the conn.getURL() is actually different URL than u |
+ | // the browser page can really see the URL and use it | ||
changeImg(conn.getURL().toExternalForm()); | changeImg(conn.getURL().toExternalForm()); | ||
} | } | ||
- | |||
@JavaScriptBody(args = "url", body = "document.getElementById('img').src = url") | @JavaScriptBody(args = "url", body = "document.getElementById('img').src = url") | ||
private static native void changeImg(String url); | private static native void changeImg(String url); |