 |
 |
|
 |
06-01-2009, 12:21 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Oct 2008
Posts: 1,658
|
UIWebView loading a local html file using javascript
Hello All,
Just as a learning exercise I took a webpage that I have, which runs some javascript functions, and am trying to bring it into an UIWebView. For simplicity sake lets just say that i have two documents; an html document and a . js javascript file which it includes. On my original website I fill out a form and hit submit; which calls the javascript function to alter the page a bit based on the input.
Now I have brought these two files into my xCode project and loaded the html file locally into a UIWebView. However, when i hit submit; nothing happens. Is there something special I need to do to make the javascript work as it did on the original web version? Thanks.
|
|
|
06-01-2009, 03:49 PM
|
#2 (permalink)
|
|
Registered Member
Join Date: Oct 2008
Posts: 1,658
|
Quote:
Originally Posted by scotopia
Hello All,
Just as a learning exercise I took a webpage that I have, which runs some javascript functions, and am trying to bring it into an UIWebView. For simplicity sake lets just say that i have two documents; an html document and a . js javascript file which it includes. On my original website I fill out a form and hit submit; which calls the javascript function to alter the page a bit based on the input.
Now I have brought these two files into my xCode project and loaded the html file locally into a UIWebView. However, when i hit submit; nothing happens. Is there something special I need to do to make the javascript work as it did on the original web version? Thanks.
|
Any thoughts?
|
|
|
06-01-2009, 08:21 PM
|
#3 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,569
|
Quote:
Originally Posted by scotopia
Any thoughts?
|
Fist make sure the javascript works when you drag the HTML directly into safari on your desktop machine. If it doesn't work there, you have a more basic problem, and it's easier to debug on the desktop.
Then, see if mobile safari is the problem. You can put your HTML on a server, enable errors in mobile safari (it's in the settings app) and see if you're getting a javascript error in your onsubmit function.
You could also implement webView:didFailLoadWithError: in your UIWebView's delegate - see if you're getting any errors there. That probably won't show any Javascript errors, but you'll probably get something there if your onsubmit function fails, and it tries to go to the (unspecified?) action of your form.
I don't know any way to debug in the UIWebview, other than the old fashioned way - adding alert() boxes at each step of the script to see how far you're getting. On the form submit, inside the function itself, etc.
__________________
|
|
|
06-02-2009, 01:30 PM
|
#4 (permalink)
|
|
Registered Member
Join Date: Oct 2008
Posts: 1,658
|
Quote:
Originally Posted by smasher
Fist make sure the javascript works when you drag the HTML directly into safari on your desktop machine. If it doesn't work there, you have a more basic problem, and it's easier to debug on the desktop.
Then, see if mobile safari is the problem. You can put your HTML on a server, enable errors in mobile safari (it's in the settings app) and see if you're getting a javascript error in your onsubmit function.
You could also implement webView:didFailLoadWithError: in your UIWebView's delegate - see if you're getting any errors there. That probably won't show any Javascript errors, but you'll probably get something there if your onsubmit function fails, and it tries to go to the (unspecified?) action of your form.
I don't know any way to debug in the UIWebview, other than the old fashioned way - adding alert() boxes at each step of the script to see how far you're getting. On the form submit, inside the function itself, etc.
|
Thanks for the reply smasher.
It worked on my desktop; and I threw it up on a webserver and browsed to it using mobile safari and that worked as well...hmm.
Last edited by scotopia; 06-02-2009 at 01:32 PM.
|
|
|
07-09-2009, 11:48 AM
|
#5 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,569
|
Loading javascript in a UIWebView
Ancient thread bump, for the benefit of googlers. May be the same problem as this thread:
Loading local .js file into uiwebview problem
__________________
|
|
|
07-09-2009, 12:12 PM
|
#6 (permalink)
|
|
Registered Member
Join Date: Oct 2008
Posts: 1,658
|
Quote:
Originally Posted by smasher
|
Thanks Smasher, I forgot I was trying to figure this out (got sidetracked by other things  ). I don't remember getting warnings like this guy was getting; but it certainly seems like this could be my issue; I'll check it out when I get home from work and report back.
|
|
|
11-05-2009, 03:51 AM
|
#8 (permalink)
|
|
Registered Member
Join Date: Jun 2009
Posts: 171
|
How to do a search feature in PDF loaded in UIWebView?Plz help me
Quote:
Originally Posted by smasher
|
I have a pdf loaded onto a UIWebView. I want to do search of a string in that PDF. So I used these steps
Code:
NSString* addressText =[NSString stringWithFormat:searchBar.text];
NSString *javaSript=[NSString stringWithFormat:
@"var highlightStartTag = \"<font style='color:blue; background-color:yellow;'>\";"
" var highlightEndTag = \"</font>\";"
" var bodyText = document.body.innerHTML;"
" var searchTerm=%@;"
" var newText = \"\";"
" var i = -1;"
" var lcSearchTerm = searchTerm.toLowerCase();"
" var lcBodyText = bodyText.toLowerCase();"
" while (bodyText.length > 0){"
" i = lcBodyText.indexOf(lcSearchTerm, i+1);"
" if (i < 0){"
" newText += bodyText;"
" bodyText = "";}"
" else{"
" if (bodyText.lastIndexOf(\">\", i) >= bodyText.lastIndexOf(\"<\", i)){"
"if (lcBodyText.lastIndexOf(\"/script>\", i) >= lcBodyText.lastIndexOf(\"<script\", i)){"
" newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;"
" bodyText = bodyText.substr(i + searchTerm.length);"
" lcBodyText = bodyText.toLowerCase();"
" i = -1;"
" }"
" }"
" }"
" }"
" bodyText = newText;"
" document.body.innerHTML = bodyText;",addressText];
[webView stringByEvaluatingJavaScriptFromString:javaSript];
But it seems to have no effect. Dont this work on a pdf loaded onto a webView. I have been doing this thing for about 3 days. Plz give me some idea.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 445 |
| 48 members and 397 guests |
| Abel95, andluclive, appie, bensj, ChrisMayer, cmpak, csaawariya, davidloew, Desdichado, Dorald, dre, far100, fiddy, firearasi, FlukeDude, gomugroup, HemiMG, hm50, iphonig, javaconvert, jingledale, joeprogrammer, johnnybluejeans, Jompe71, Kalimba, Kilby, kilobytedump, kwanwoolee, LemonMeringue, LightRoom, Locker, malaki1974, Mopedhead, oldmicah, pikabli, ryguy2503, sayer, SimonHodgkiss, skunk, stevek, ttthebest, Vernon, vikinara, wyoskibum, xiko, ZunePod, _nivek |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,208
Threads: 38,991
Posts: 171,023
Top Poster: smasher (2,569)
|
| Welcome to our newest member, JDBurgie |
|