How to display local html page in browser control

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

seamus_waldron
Posts: 11
Joined: Mon Dec 13, 2010 4:12 pm

How to display local html page in browser control

Post by seamus_waldron » Sun Jan 02, 2011 1:00 pm

I am trying to use the Browser Example code from the LiveCode installation to display local HTML pages in an instance of the browser control. I can't figure it out.

My setup.
I have two HTML pages and relevant images and javascript files in a sub-directory called 'www'. The main HTML file is called index.html.
I have used 'copy files' to include the contents of folder 'www' in my application.

I have modified the example code on line 18 of the card from

iphoneControlSet sBrowserId, "url", "http://www.google.com"

to

phoneControlSet sBrowserId, "url", "file://" & specialFolderPath("engine") & "www/index.html"

and to

phoneControlSet sBrowserId, "url", specialFolderPath("engine") & "www/index.html"

with no joy.

I have tried tinkering with the constructed URL (e.g. adding in an extra / before the www), but can't get anything to work.

Any suggestions?

Regards

Seamus

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to display local html page in browser control

Post by Mark » Mon Jan 03, 2011 12:41 pm

Hi Seamus,

Your URL needs to start with "file:///" (three slashes).

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

rozek
Posts: 151
Joined: Mon Jun 19, 2006 2:29 pm
Contact:

Re: How to display local html page in browser control

Post by rozek » Mon Jan 03, 2011 2:18 pm

Hello!

I am trying the same - since several hours - but never succeeded.

While it is possible to load external documents (using the "http://" prefix) I never succeeded loading internal ones (using the "file://" or "file:///" prefix.

I tried to "debug" my code using "put" statements and

- did not get "BrowserLoadRequest" messages
- got "BrowserStartedLoading" requests without the URLs (which makes them useless)
- got "BrowserLoadFailed" requests without URLs (but error messages that the document could not be found)

I tried any possible combination with/without URLEncode (which even encodes slashes "/" which might be counterproductive) and with/without specialFolderPath("engine") (which seems to point to the correct location, on the simulator at least)

Sometimes, I also get error messages like "The operation couldn't be completed. (WebKitErrorDomain error 101.)"

Is there anything else I should consider?
Kind regards,

Andreas Rozek

rozek
Posts: 151
Joined: Mon Jun 19, 2006 2:29 pm
Contact:

Re: How to display local html page in browser control

Post by rozek » Mon Jan 03, 2011 2:56 pm

Hmmm,

I think I got somewhat further. After realizing, that the console has to be actively reloaded(!) or you may get outdated log messages, I found that, when you use an expression like

Code: Select all

"file://" & specialFolderPath("engine") & ...
the two slashes after "file:" are correct!

Instead, you have to append another "/" after specialFolderPath("engine"), like

Code: Select all

"file://" & specialFolderPath("engine") & "/index.html"
Additionally: DO NOT TRUST THE SIMULATOR! After simply trying an application, which failed on the simulator (but produced good-looking console outputs) on a real device, the local file got loaded!

I still have problems because some "inner" files (loaded by "index.html") did not get loaded - but that's another issue...
Kind regards,

Andreas Rozek

seamus_waldron
Posts: 11
Joined: Mon Dec 13, 2010 4:12 pm

Re: How to display local html page in browser control

Post by seamus_waldron » Mon Jan 03, 2011 3:39 pm

So, this is the line to load the local page that I used:

iphoneControlSet sBrowserId, "url", "file://" & specialFolderPath("engine") & "/www/index.html"

It absolutely does NOT work in the simulator, but guess what? It DID work on the real device.

No idea what is going on.

Many thanks for the suggestion to just load it to the device,

Seamus

rozek
Posts: 151
Joined: Mon Jun 19, 2006 2:29 pm
Contact:

Re: How to display local html page in browser control

Post by rozek » Mon Jan 03, 2011 3:43 pm

Hi Seamus!

Your post is the only positive outcome of my work with LiveCode iOS deployment today - it seems to still contain LOTS of bugs as I was completely unable to finish even the simplest of my attempts today (no textures, broken images, non-working browser callbacks and now the complete loss of being able to produce standalones after a crash of the IDE :-( )

Hopefully, you are more successful than I have been!
Kind regards,

Andreas Rozek

rozek
Posts: 151
Joined: Mon Jun 19, 2006 2:29 pm
Contact:

Re: How to display local html page in browser control

Post by rozek » Mon Jan 03, 2011 4:21 pm

Just as a side-node:

even on a real device you won't get any "BrowserLoadRequest" messages! The foreseen possibility to intercept (and forbid or ignore) the loading of certain resources is therefore simply not available!

And the benefit of other messages is often doubtful:

- "BrowserStartedLoading" does not contain the URL of the resource which started loading
- "BrowserLoadFailed" comes without URL as well
- "BrowserFinishedLoading" seems to be the only message which works as foreseen - but it seems to be sent only for resources that were explicitly requested through "iPhoneControlSet BrowserId, "url", ..."

[edit]Indirectly loaded resources (i.e. those loaded by the document YOU requested through "iPhoneControlSet BrowserId, "url", ..." seem never to trigger any callback messages - even on failure (and regardless of their scheme) This makes it impossible to communicate between an HTML document and the LiveCode application (unless there is another method which I don't think of right now)
Last edited by rozek on Mon Jan 03, 2011 4:30 pm, edited 1 time in total.
Kind regards,

Andreas Rozek

seamus_waldron
Posts: 11
Joined: Mon Dec 13, 2010 4:12 pm

Re: How to display local html page in browser control

Post by seamus_waldron » Mon Jan 03, 2011 4:28 pm

Okay, I have total success!!!

It turns out that if you have spaces in the full URL of the local file, the page will not load.

In the simulator, the function specialFolderPath("engine") will return a path that has several spaces (/Library/Application Support/iPhone Simulator/etc etc)

On the device, specialFolderPath("engine") will return a path with no spaces in it IF your Standalone name DOES NOT HAVE SPACES IN IT. If your standalone name has spaces in it, then once again you are stuffed.

You have to replace the spaces in the URL with %20 (replacing with a + will not work).

So, to get a local HTML page to load in both the simulator and the device, you have to do something like this:

Code: Select all

put "file://" & specialFolderPath("engine")  & "/www/index.html" into  localURL
replace " " with "%20" in localURL
iphoneControlSet sBrowserId, "url", localURL

Voila! Bit of a nightmare, but it does work.

Seamus

rozek
Posts: 151
Joined: Mon Jun 19, 2006 2:29 pm
Contact:

Re: How to display local html page in browser control

Post by rozek » Mon Jan 03, 2011 4:32 pm

Great!

Thanks, Seamus (aren't we a winning team together?)
Kind regards,

Andreas Rozek

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to display local html page in browser control

Post by bn » Mon Jan 03, 2011 8:19 pm

Hi Seamus,
replace " " with "%20" in localURL
look at urlEncode in the dictionary. It does what you want.

regards

Bernd

seamus_waldron
Posts: 11
Joined: Mon Dec 13, 2010 4:12 pm

Re: How to display local html page in browser control

Post by seamus_waldron » Mon Jan 03, 2011 10:20 pm

Hi Bernd ,

I did look at URLEncode, but couldn't get it to work correctly (I'm still new to LiveCode, so I suspect I was constructing the statement incorrectly).

However, in this instance I do not need to do a full URLEncode as the only thing I want to do is to remove the spaces. Also, the replace function should be quicker than URLEncode or replaceText.

However, for completeness, could you provide an example?

Seamus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to display local html page in browser control

Post by bn » Mon Jan 03, 2011 10:34 pm

Hi Seamus,

here is a little stack that does a urlEncode.

Kind regards

Bernd
Attachments
testURLencode.livecode.zip
(1.03 KiB) Downloaded 522 times

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to display local html page in browser control

Post by Mark » Mon Jan 10, 2011 11:56 pm

Hi,

If you do a urlEncode, you might need to restore some of the slashes and colon(s) and you might need to replace the + sign by %20.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

seamus_waldron
Posts: 11
Joined: Mon Dec 13, 2010 4:12 pm

Re: How to display local html page in browser control

Post by seamus_waldron » Tue Jan 11, 2011 7:48 am

I can confirm that, I finally had a chance to look at the stack with the URLEncode example in it (thanks! :-) and the spaces were being converted to +, when for this solution you need the spaces to be converted to %20.

Seamus

jstarkman
Posts: 47
Joined: Wed Mar 16, 2011 4:39 am

Re: How to display local html page in browser control

Post by jstarkman » Sat Mar 26, 2011 6:47 pm

Since the folks here have some experience with the iOS browser, maybe you can help me.

I've been successful in loading a local PDF file for display using the Mobile Browser sample, but I can't seem to trap touch events on the browser object with LiveCode handlers. I'm using the simulator. Touching (click/drag) on the simulator moves the PDF around on the display, and I can do pinch gestures etc, but I can't do something as simple as trap a touchEnd event. Any ideas?

Thanks,

Joel

Post Reply