|
Re: SWT Browser, loading a page and javascripts from file system. (SOLVED) [message #550382 is a reply to message #550251] |
Fri, 30 July 2010 07:44 |
Christophe Bouhier Messages: 937 Registered: July 2009 |
Senior Member |
|
|
Hi,
I found a solution. It's a bit of a hack, but it works!
Put this in the plugin Activator:
public static String getAbsoluteURL(String path){
Bundle bundle = Platform.getBundle(PLUGIN_ID);
if (!BundleUtility.isReady(bundle)) {
return null;
}
String loc = bundle.getLocation();
loc = loc.substring(loc.indexOf("file:"), loc.length()).concat(path);
return loc;
}
What it does:
1. It gets the bundle for this plugin.
2. It gets the absolute location in String format. The location has some
polutated prefix, which we strip off.
3. What you get is a nice absolute URL starting with file:/../[path to
the relative location]
Use this location in your SWT.browser setURL() and the local javascripts
will also in the SWT. (See below the relative path starting with
'lib/flot').
<script language="javascript" type="text/javascript"
src="lib/flot/jquery.js"></script>
<script language="javascript" type="text/javascript"
src="lib/flot/jquery.flot.js"></script>
The way I use this, is by transforming the contents of an EMF model
to i.e. a json file which the HTML scripts use to display in am SWT
Browser.
Cheers Christophe
Christophe Bouhier wrote:
> Hi,
>
> Like any browser, if I open a local file, I would have to set the path
> to the javascripts relative to the html file.
>
> Now, I use SWT Browser setText() to load an html formated script with
> references to javascripts, however these are not loaded.
>
> I load the html from my RCP runtime. Is there a way to make the SWT
> Browser also load the scripts from the runtime bundle? (I have tried a
> relative path from the bundle entry like /web/link/myscript.js).
>
>
> thanks Christophe
|
|
|
|
Powered by
FUDForum. Page generated in 0.02736 seconds