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.
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.
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.
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.
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.
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.