Help with path to Javascript files

I have a WebHTML Viewer on a page that is set to show an HTML file that I have dragged into my project.
Within this HTML file there are two lines within the section that need to load a couple of Javascript files which are stored locally on my desktop.

I’m having trouble working out what to put as the path where the xxx’s are below:

This is running on OSX 10.8.4

Cheers

Paul

You need to use a WebFile. Make a property in your project, somewhere global, name it jscode. Then in app.open:

Jscode = new WebFile Jscode.data = yourJavascriptCode // use a constant to store the JavaScript code Jscode.Session = Nil // this makes it available to any session Jscode.MIMEType = "text/javascript"

Now, in your HTML, insert jscode.URL and it will point to the right location.

Greg,

for some JavaScript files, this is good solution. But, if you have some hundreds of pictures or css files and you need to load them on your web application, it is not good solution to load everything on your application. It would better, to have the opportunity to load directly from the harddisk, rather than to load everything on application memory.

BR/Antonis

Hi Greg

Thanks for your reply, I followed your instructions and managed to get the page to load correctly.
Following on from Antonis’ comments, is there an easy way to do this if you need to load lots of libraries?
I guess I could create an array of WebFiles and store them all there?

Cheers

Paul

[quote=29930:@Paul Finer]Following on from Antonis’ comments, is there an easy way to do this if you need to load lots of libraries?
I guess I could create an array of WebFiles and store them all there?[/quote]
If the libraries are hosted somewhere else, then just reference them directly from there. If you need/must keep them local, then use the CGI deployment option (instead of standalone*) and store the files on your server and let the web server handle them.

  • You can also do this in standalone if you run it behind a reverse proxy or something similar.

Another solution would be to write your own handler using the App.HandleSpecialURL. You could handle things called to /api/assets/ as pointing to your desktop or something like that.

The problem is that you really shouldn’t blindly send files down to the browser. A Mime Type should always be included. While most browsers will figure it out on their own, you may not always be so lucky.

Greg,

good idea, to handle through App.HandleSpecialURL. So, if on css or javascript file, the image url is “/api/assets/image.gif”, to open a webfile for that… I will try and inform the community about the results.

BR/Antonis

It’s working on windows all browsers …

on a css file, i have the following command :
background-image: url(’/special/imagefolder/image.gif’);

on HandleSpecialURL, I have the following code :

[code] dim fPath as string = Request.Path
dim f as FolderItem
dim mb as MemoryBlock
dim bs as BinaryStream

f = GetFolderItem(“xojoImages/” + fPath)

if f.Exists then
bs = bs.Open(f,False)
mb = bs.Read(bs.Length)
bs.Close
end if

Request.Print mb

return true[/code]

So, when the css file calls the image url, then through HandleSpecialURL event, it download it on browser.

Thanks Greg again…

I hope, that it does not holds the image on memory and clean the variables when the procedure returns. Correct ?

BR/Antonis

Yes. Everything gets reset.