Вы находитесь на странице: 1из 4

********************************************************************************

*******************************************
If Web view is added as sub view before its content gets loaded, web view will g
et shown with white color background. To avoid this, add web view as child only
in its delegate methods - didFinishLoad.
********************************************************************************
*******************************************
Do not change web view frame once its loading is over. Otherwise, webview conten
t will be big in font size. Preferably set web view frame before calling load me
thods - loadHTMLString.
How to do this if web view is used inside UITableView?
1) Set webview frame, (0, 0, 320, height)
2) call loadHTMLString on it
3) In webViewDidFinishLoad: method, call loadData on table
4) In cellForRowAtIndexPath, add web view as child of cell's content view.
********************************************************************************
*******************************************
How to find the content height of an UIWebView? If UIWebView needs to be set in
UITableView, height is needed.
http://stackoverflow.com/questions/745160/how-to-determine-uiwebview-height-base
d-on-content-within-a-variable-height-uita
********************************************************************************
*******************************************
How to make a web view that has content height as 900px non scrollable - i.e. co
ntent below 320px could not be seen?
Set web view height as 900px. Then, scrolling wouldn't work.
********************************************************************************
*******************************************
How to make window.open() javascript function to work in SDK 3.0 and below:
http://www.icab.de/blog/2009/08/05/webkit-on-the-iphone-part-2/
http://www.gibsontang.com/?p=483
********************************************************************************
*******************************************
--> Verify whether base url given in [webView loadHTMLString:baseUrl:] is used a
s referer url in NSURLRequest passed to web view delegate method.
********************************************************************************
*******************************************
--> Use style attribute of body element to adjust top and left margin of html co
ntent. By default, left and top margins are not zero and whitespace would appear
in page left and page top.
<body style = "margin-top: 0px; margin-left: 0px">
</body>
To make html page occupy full size of iphone, use meta tag.
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user
-scalable=no"/>
</head>
********************************************************************************
*******************************************
--> How to set view controller's title as title of html page loaded in UIWebView
?
- (void)webViewDidFinishLoad:(UIWebView*)webView
{
self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.
title"];
}
********************************************************************************
*******************************************
--> If a link will open in new window, i.e. has target attribute's value as _bla
nk, clicking that link wouldn't result a call to shouldStartLoadWithRequest in S
DK less than 3.1. Remove that _blank attribute:
http://blog.mikeweller.com/2009/06/uiwebview-doesnt-open-targetblank-links.html
- (void)webViewDidFinishLoad:(UIWebView *)_webView
{
NSString* js = @"\
var d = document.getElementsByTagName('a');\
for (var i = 0; i < d.length; i++) {\
if (d[i].getAttribute('target') == '_blank') {\
d[i].removeAttribute('target');\
}\
}\
";
[_webView stringByEvaluatingJavaScriptFromString:js];
}
********************************************************************************
*******************************************
UIWebView doesn't render its content when it is off-screen. User has to double c
lick web view to see the content:
http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/
********************************************************************************
*******************************************
isLoading says whether loadRequest is still going on. It doesn't talk about whet
her loadHTMLString goes on or completed.
********************************************************************************
*******************************************
while releasing UIWebView: a) set its delegate to nil. b) if webview is still lo
ading, stop it.
********************************************************************************
*******************************************
shouldStartLoadWithRequest of UIWebViewDelegate gives url that will be loaded in
web view along with how this url was received. Whether user has clicked or post
ed the link or the link was obtained in some other forms.
UIWebViewNavigationTypeLinkClicked
********************************************************************************
*******************************************
UIWebView - like any other UI control - loads content on main thread. If the con
tent is static, there wouldn't be any problem. But if the content is dynamic and
its loading takes time, this would block main thread.
[stringByEvaluatingJavaScriptFromString:] talks about this problem indirectly.
********************************************************************************
*******************************************
Assume that a html document doesn't have static content - it loads content dynam
ically, say using javascript.
Assume that we use loadHTMLString and loading of dynamic content fails, [webView
:didFailLoadWithError:] delegate method wouldn't be called.
********************************************************************************
*******************************************
NSString *html = @"<html></html>";
UIWebView* webView = // create it
[webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.hitchhike
r.com/message"]];
The baseURL is the base URL that relative URLs in the HTML are based on. So, in
the example, with the base URL set as http://www.hitchhiker.com/message , if, in th
e HTML there was something like img src= test.jpg , then the image that would be loa
ded would be at http://www.hitchhiker.com/message/test.jpg
********************************************************************************
*******************************************
--> How to give images within documents directory to a webview that loads html a
page?
NSString* documentsDirectoryUrl = [[NSBundle mainBundle] resourcePath];
documentsDirectoryUrl = [documentsDirectoryUrl stringByReplacingOccurrencesOfStr
ing:@"/" withString:@"//"];
documentsDirectoryUrl = [documentsDirectoryUrl stringByReplacingOccurrencesOfStr
ing:@" " withString:@"%20"];
UIWebView* webView;
NSString* htmlString = @"";
[webView loadHTMLString:htmlString
baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//"
,documentsDirectoryUrl]]];
********************************************************************************
*******************************************
http://iphoneincubator.com/blog/tag/uiwebview
********************************************************************************
*******************************************
--> If a webview is already loading something and we requset second loading, [we
bview:didFailLoadWithError:] will be called with error code NSURLErrorCancelled.
NSURLErrorCancelled's value is -999.
http://stackoverflow.com/questions/1024748/how-do-i-fix-nsurlerrordomain-error-9
99-in-iphone-3-0-os
********************************************************************************
*******************************************
--> Changing webview based on device orientation:
http://ajaxian.com/archives/iphone-windowonorientationchange-code
http://mrgan.tumblr.com/post/98547533/fullscreen-web-apps
Keyword is document.body.setAttribute and document.body.removeAttribute.
********************************************************************************
*******************************************

Вам также может понравиться