PDA

View Full Version : UIWebView to browse local files




dusker
Jun 2, 2009, 05:42 AM
Hi Everyone,
i have a following problem:
i'd like to build a simple offline webpage browser, the webpage is pure HTM files. The structure looks like this:

index.htm
/subpages/page1.htm
/subpages/page2.htm

Ofcourse there're a lot of subpages not just two, and here's my question. I'm able to load the index htm into UIWebView using loadrequest, but index.htm contains links to subpages in a form of <a href="subpages/page1.htm">page1</a> and those links won't work. Can anyone help out?

thanks for help in advance
peter



firewood
Jun 2, 2009, 10:20 AM
Did you create that directory structure wherever you put your files? (bundle or sandbox Documents directory)?

ghayenga
Jun 2, 2009, 10:21 AM
Hi Everyone,
i have a following problem:
i'd like to build a simple offline webpage browser, the webpage is pure HTM files. The structure looks like this:

index.htm
/subpages/page1.htm
/subpages/page2.htm

Ofcourse there're a lot of subpages not just two, and here's my question. I'm able to load the index htm into UIWebView using loadrequest, but index.htm contains links to subpages in a form of <a href="subpages/page1.htm">page1</a> and those links won't work. Can anyone help out?

thanks for help in advance
peter

Look at the UIWebViewDelegate's shouldLoadRequest method. When they click on the link this gets called and you load the new htm file into it yourself.

PhoneyDeveloper
Jun 2, 2009, 10:50 AM
I think you need to specify the baseURL in one of the methods that takes that parameter to load your index.htm file.

dusker
Jun 2, 2009, 03:07 PM
Look at the UIWebViewDelegate's shouldLoadRequest method. When they click on the link this gets called and you load the new htm file into it yourself.

what do you mean yourself? if the two htm files are in rood directory of a bundle hyperlinks work perfectly. issues are when the folders get involved.

Did you create that directory structure wherever you put your files? (bundle or sandbox Documents directory)?

i just dragged and dropped the folder into resources in xcode

I think you need to specify the baseURL in one of the methods that takes that parameter to load your index.htm file.

how to specify baseUrl in loadrequest method?

PhoneyDeveloper
Jun 2, 2009, 07:34 PM
how to specify baseUrl in loadrequest method?

You can't. You need to use one of the other load methods.

Try googling UIWebView and baseURL. This is a common question.

See this for example

http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/

dusker
Jun 3, 2009, 04:07 AM
You can't. You need to use one of the other load methods.

Try googling UIWebView and baseURL. This is a common question.

See this for example

http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/

Hi,
thanks for all the answers so far.
Would you mind providing me with one hint, meaningly what other method would allow me to load html file into uiwebview?
greetings
peter

firewood
Jun 3, 2009, 06:58 AM
i just dragged and dropped the folder into resources in xcode

That doesn't, by itself, create the directories you need.

PhoneyDeveloper
Jun 3, 2009, 11:15 AM
Would you mind providing me with one hint, meaningly what other method would allow me to load html file into uiwebview?

Um, loadHTMLString:baseURL: and loadData:MIMEType:textEncodingName:baseURL: