problem with file:// URL

In trying to setup a help system in my web app, preparing the help pages in RapidWeaver, I’m apparently unable to show them in a HTMLViewer.

This code placed in the Open event of a HTMLViewer properly works for showing the external page:

[code]dim url as string=“http://www.xojo.com

me.URL=url

URLfield1.Text=url
URLfield1.Target=2
URLfield1.URL=url
[/code]

The web page is shown in the HTMLViewer and if I click on the WebLink named URLfield1 the page opens in the browser.

But this code doesn’t show anything in the HTMLViewer and if I click on the WebLink URLfield nothing happens:

[code]dim f as folderItem
f=SpecialFolder.Desktop.Child(“TestSite”).Child(“index.html”)

if f<>nil and f.Exists then

me.URL="file://"+f.ShellPath

URLfield.Text="file://"+f.ShellPath
URLfield.Target=2
URLfield.URL="file://"+f.ShellPath

else

MsgBox "Error in URL definition"

end if
[/code]

The URL is coming out as I expect

file:///Users/locvac/Desktop/TestSite/index.html

and if I use the above URL straight in Safari the page is properly shown. What am I doing wrong?

Franco

PS: this is on Mac OS 10.8.5, and Xojo 2014 r2.1

[quote=135798:@Franco Vaccari]In trying to setup a help system in my web app, preparing the help pages in RapidWeaver, I’m apparently unable to show them in a HTMLViewer.

This code placed in the Open event of a HTMLViewer properly works for showing the external page:

[code]dim url as string=“http://www.xojo.com

me.URL=url

URLfield1.Text=url
URLfield1.Target=2
URLfield1.URL=url
[/code]

The web page is shown in the HTMLViewer and if I click on the WebLink named URLfield1 the page opens in the browser.

But this code doesn’t show anything in the HTMLViewer and if I click on the WebLink URLfield nothing happens:

[code]dim f as folderItem
f=SpecialFolder.Desktop.Child(“TestSite”).Child(“index.html”)

if f<>nil and f.Exists then

me.URL="file://"+f.ShellPath

URLfield.Text="file://"+f.ShellPath
URLfield.Target=2
URLfield.URL="file://"+f.ShellPath

else

MsgBox "Error in URL definition"

end if
[/code]

The URL is coming out as I expect

file:///Users/locvac/Desktop/TestSite/index.html

and if I use the above URL straight in Safari the page is properly shown. What am I doing wrong?

Franco

PS: this is on Mac OS 10.8.5, and Xojo 2014 r2.1[/quote]

Mac OS X has issues showing local files addressed through file:// in desktop, this maybe the same phenomenon hitting Web Edition. I confirm me.url simply does not work.

You may want to load the page into a string and then LoadPage the source into your HTMLViewer. I tested successfully the code below :

[code]Sub Open()
dim f as folderItem
f=SpecialFolder.Desktop.Child(“index.html”)
dim HTMLSource as string

if f<>nil then
if f.Exists then

  // Be aware that TextInputStream.Open coud raise an exception
  Dim t As TextInputStream
  Try
    t = TextInputStream.Open(f)
    t.Encoding = Encodings.MacRoman
    HTMLSource = t.ReadAll
  Catch e As IOException
    t.Close
    MsgBox("Error accessing file.")
  End Try
End If


me.LoadPage(HTMLSource)
'URLfield.Text="file://"+f.ShellPath
'URLfield.Target=2
'URLfield.URL="file://"+f.ShellPath

else

MsgBox "Error in URL definition"

end if
End Sub
[/code]

Don’t mix a shell path with a URL path, look at f.URLPath instead. These are two different systems.

@Michael:

Thanks. Tried that, it loads the page, but since the html code generated by RapidWeaver refers to other files, those are not read in. Styles are also lost, so while this would work for simple standalone pages, I’m afraid it isn’t a solution for a site made of several pages.

BTW, what do you mean by [quote]Mac OS X has issues showing local files addressed through file://[/quote]. Does it mean “Xojo on OS X” or is it truly a OS problem? But that file:// URL written in the address field of Safari works perfectly.

@Sam:

I spent the whole afternoon yesterday trying to get something out. I’m sure I tried experimenting also with f.URLPath, with no luck.

The URL file:/// sent to a users browser tries to load a file from the users machine not your site

Sure hope not as the local help uses this extensively

Understood, and that explains a lot…

So what is the correct way to visualise in a HTMLViewer the pages I’ve prepared with RapidWeaver? I’m setting up a Linux VM where the web app is running as a CGI under apache, and is actually reached just by the host computer through the internal network adapter (with URL http://172.16.10.101/~vaccari/cgi-bin/……)

I imagine I’ve to put the files in ~vaccari/public_html, and then how should the URL be defined from within the web app? And what about the URL when debugging?

Thanks

Since the URL is going to be on the client browser you need to form the uRL as one that points back to your site same as any other URL

Simply try in the browser on your desktop something like
http://172.16.10.101/~vaccari/public-html/index.html
(or whatever the page name is)
You may not even need all that depending on how the web server is set up

Experiment in Safari, Chrome or whatever other browser you’re using manually

Ok, will try that. But thinking back at the debugging stage, when I run the web app from within Xojo, and the browser window pos up, shouldn’t in that case the URL file:///Users/locvac/Desktop/TestSite/index.html be a valid one?

Its valid because those files ARE on your machine
When you put your app on the internet thats no longer valid for everyone else (it would still work for you because they are still on your machine)

Yes, that’s what I mean. It is valid, but for whatever reason it doesn’t show the page in the HTMLViewer, while it shows it properly in Safari

I should have said the issue is in the media player.

Anyway, for my private network configuration, this URL set in the open event of the HTMLViewer does the trick:

me.URL=“http://172.16.10.101/~vaccari/index.html

Problem solved, apart from the fact that I can’t load the html pages while debugging.

And of course, thanks to all who replied!

[quote=135905:@Franco Vaccari]Anyway, for my private network configuration, this URL set in the open event of the HTMLViewer does the trick:

me.URL=“http://172.16.10.101/~vaccari/index.html

Problem solved, apart from the fact that I can’t load the html pages while debugging.[/quote]

#if DebugBuild me.URL="file:/// ...... whatever #else me.URL="http://172.16.10.101/~vaccari/index.html" #endif

The problem being that

me.URL="file:/// …… whatever

does not render in the HTMLViewer, at least in my experience…

[quote=135994:@Franco Vaccari]The problem being that

me.URL="file:/// …… whatever

does not render in the HTMLViewer, at least in my experience…[/quote]

Indeed it does not work. But since a web app is intended to be placed on a host, why not simply upload your pages to the host and directly use their URL, instead of trying to fetch the files locally ?

Sure. In my specific case it means that while debugging I must have my virtual machine running, which is somehow annoying for RAM an CPU usage. I admit I’m working with a quite peculiar configuration… :slight_smile:

You can also use the specialurl way, but you will have to serve the files through your app.

App.HandleSpecialURL event permits you to serve files that are requested in the form of

http://127.0.0.1:8080/specialurl/Test.html
or
http://127.0.0.1:8080/api/Test.html
In such event you compare Request.Path to the name of the file, load it from disk, then send it through Request.Print to the client. You can manage an entire directory structure through that event, including pictures.

It is not as simple as uploading the files to a web space, but it works.