开发者

How to submit a form in a UIWebView loaded with HTMLString:baseURL:?

oHi,

I'm displaying a html page which contains a form with some input text fields and a submit button.

  • If i display the page using loadRequest: everything works fine.
  • If i display the same page using loadHTMLString:baseURL: the submit button is not working anymore.

The adress which is supposed to be called is :

http://..../lire.php?id=33570#bloc_commentaire

If i log the adress it tries to reach i got :

applewebdata://BF6F3D92-9F36-40CA-A3EB-BCD3F14852B6#bloc_commentaire

Do you have any idea of what i should do to be able to post a form loaded statically using loadHTMLString:baseURL: 开发者_运维技巧?

Thanks, Vincent


The problem occurs because your web view doesn't know where to post the data because the html is loaded from a string and not a specific web server.

Make sure you are setting baseURL correctly in your call to

 [webView loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL]

Details:

When the webview finds a relative url in the html, it joins it with the baseURL to form an absolute url which can be used to submit or click on. For instance:

Given http://www.test.com/foo/ as baseURL and a relative url tag lke <a href="bar/hello.php">click me</a>

When the user clicks on the link, the view will make a request to http://www.test.com/foo/bar/hello.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜