Page 1 of 2

How to display local html page in browser control

Posted: Sun Jan 02, 2011 1:00 pm
by seamus_waldron
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

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 12:41 pm
by Mark
Hi Seamus,

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

Mark

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 2:18 pm
by rozek
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?

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 2:56 pm
by rozek
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...

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 3:39 pm
by seamus_waldron
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

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 3:43 pm
by rozek
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!

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 4:21 pm
by rozek
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)

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 4:28 pm
by seamus_waldron
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

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 4:32 pm
by rozek
Great!

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

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 8:19 pm
by bn
Hi Seamus,
replace " " with "%20" in localURL
look at urlEncode in the dictionary. It does what you want.

regards

Bernd

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 10:20 pm
by seamus_waldron
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

Re: How to display local html page in browser control

Posted: Mon Jan 03, 2011 10:34 pm
by bn
Hi Seamus,

here is a little stack that does a urlEncode.

Kind regards

Bernd

Re: How to display local html page in browser control

Posted: Mon Jan 10, 2011 11:56 pm
by Mark
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

Re: How to display local html page in browser control

Posted: Tue Jan 11, 2011 7:48 am
by seamus_waldron
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

Re: How to display local html page in browser control

Posted: Sat Mar 26, 2011 6:47 pm
by jstarkman
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