UIWebView about some properties
2011-06-27 21:53
393 查看
1. How to disable the webview could scroll.
[(UIScrollView *)[[_webView subviews] objectAtIndex:0] setBounces:NO];
2. Get the html title for webview content.
Using JavaScript:
NSString *htmlTitle = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
3. Support the UITouch Event.
Using JavaScript:
#define WebTouchJavaScript @"<script language="javascript">document.ontouchstart=function(){document.location="myweb:touch:start";}; document.ontouchend=function(){document.location="myweb:touch:end";};document.ontouchmove=function(){document.location="myweb:touch:move";}</script>"
the webview will load the html string, using this java script between the <body> and </body>.
Then, method: [_webView loadHTMLString: baseURL: ] to load. And then the web view could support the UITouch event.
The delegaete method to judge which touch event is occur.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ([components count] > 1 &&
[(NSString *)[components objectAtIndex:0] isEqualToString:@"myweb"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"touch"]) {
//Dispatch the UITouch Event and handle with reference actions.
NSLog(@"touch : %@", [components objectAtIndex:2]);
4,禁止选中文本
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
[(UIScrollView *)[[_webView subviews] objectAtIndex:0] setBounces:NO];
2. Get the html title for webview content.
Using JavaScript:
NSString *htmlTitle = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
3. Support the UITouch Event.
Using JavaScript:
#define WebTouchJavaScript @"<script language="javascript">document.ontouchstart=function(){document.location="myweb:touch:start";}; document.ontouchend=function(){document.location="myweb:touch:end";};document.ontouchmove=function(){document.location="myweb:touch:move";}</script>"
the webview will load the html string, using this java script between the <body> and </body>.
Then, method: [_webView loadHTMLString: baseURL: ] to load. And then the web view could support the UITouch event.
The delegaete method to judge which touch event is occur.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ([components count] > 1 &&
[(NSString *)[components objectAtIndex:0] isEqualToString:@"myweb"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"touch"]) {
//Dispatch the UITouch Event and handle with reference actions.
NSLog(@"touch : %@", [components objectAtIndex:2]);
4,禁止选中文本
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
相关文章推荐
- Some Career Myths about IT Pros
- Some information about TCP socket in WINCE
- Some Sites About .Net
- [导入]Daily Report (Learn some basic knowlage about American football.)
- Some word in English about Company website
- Some resources about Calling Conventions - cdecl, stdcall, fastcall, thiscall, etc.
- some useful link about CRM
- MaxPooling的作用 and some tips about CNN
- some thing about JSon
- The Maven Travel(4)--Starting to manage all components and talking about some essential concepts
- Some thoughts about NS2
- Some Notes About Design Pattern
- Some Tips About Layout Resource
- Some interesting facts about static member functions in C++
- Some information about CriticalSection
- A note about some errors which cause by android.R
- Some Articles About Creating SharePoint Webparts.
- Some interesting facts about static member functions in C++
- some ideAs About steAlth for rootkit
- Some tutorial about geometry