loading uiwebview from specified location - ios4

//Move to bookmarked place if page is opened from bookmark section.
- (void)webViewDidFinishLoad:(UIWebView *)webView1;
{
if(chkview == 2)
{
//Move webview to chkScrollValue position.
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"document.body.scrollTop = %d", chkScrollValue]];
// [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollBy(0,%d);",chkScrollValue]];
}
}
I'm loading my webview which was displaying html which was in resources folder and it was working fine. Now, i'm using javascript with html and this is not working anymore.

I got the solution. I was performing this task after webViewDidFinishLoad. Rather than that now I added another function and added this code in function
[self performSelector:#selector(loadBookmark) withObject:nil afterDelay:0.4];

Related

I want to open a web view instead of Browser whenever I click link on my textView

I have a lot of input text that contains linked URL on the textview field. I just want to set to default whenever I clicked any link on the textview it will pop up the webView instead of the browser.Thanks
https://developer.apple.com/library/ios/documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html
you can use this function from UITextViewDelegate:
(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
NSLog(#"URL %#",URL); // URL
// pop webkit
return NO;
}

MFSideMenu in UINavigationController not working when introduced with a modal Segue

I'm trying to integrate MFSideMenu in my project but I don't want to adopt the approach described in the GitHub depository as it defines the menu in the app delegate.
I have a login screen which will introduce a navigation controller with the main page as reported in this picture
I would like to add the support for MFSideMenu in the navigationcontroller root controller using this code:
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
// Custom initialization
self.sideMenuController = [[SideMenuViewController alloc] init];
UINavigationController *navigationController = self.navigationController;
MFSideMenuOptions options = MFSideMenuOptionMenuButtonEnabled|MFSideMenuOptionBackButtonEnabled
|MFSideMenuOptionShadowEnabled;
MFSideMenuPanMode panMode = MFSideMenuPanModeNavigationBar|MFSideMenuPanModeNavigationController;
MFSideMenu *sideMenu = [MFSideMenu menuWithNavigationController:navigationController
sideMenuController:sideMenuController
location:MFSideMenuLocationLeft
options:options
panMode:panMode];
sideMenuController.sideMenu = sideMenu;
}
return self;
}
When I run the app the menu button appears in my navigation bar and everything seems working fine but,if I introduce the navigation controller through a modal segue (i.e. a login screen which goes to the navigation controller in case of a correct login) the button disappears.
Any idea about how to fix it?

How to disable zoom glass/lens from UIWebView?

I have disable default call out action sheet from UIWebView by using this -
[webView stringByEvaluatingJavaScriptFromString:#"document.body.style.webkitTouchCallout='none';"];
it's working fine but the main problem is that when i tap on an image for a long time a zoom lens of UIWebView comes there and i want to disable it, is it possible? then how?
Yes a few ways but some of which are buggy.
If you don't care about userinteraction at all you can just disabled it. Then they will only be able to zoom and move around the page (but not click any links or anything).
-(void)removeInput{
UIScrollView *webViewContentView;
for (UIView *checkView in [webView subviews] ) {
if ([checkView isKindOfClass:[UIScrollView class]]) {
webViewContentView = (UIScrollView*)checkView;
break;
}
}
for (UIView *checkView in [webViewContentView subviews] ) {
checkView.userInteractionEnabled = NO;
}
}
UIWebView without Copy/Paste and selection rectangle when showing documents
However that causes all userInteraction to be disabled which might not be what you want?
To JUST disable the magnifying glass I don't think is possible (though I might be wrong?).
Ok if you don't mind disabling the text selection as well you can try this.
ObjC
[webView stringByEvaluatingJavaScriptFromString:#"document.onmousedown = function() {return false;}"];
JavaScript
document.onselectstart = function() {return false;} // ie
document.onmousedown = function() {return false;}
Source:
http://javascript.internet.com/page-details/disable-text-selection.html

How to implement event handling in uiwebview?

I have taken a webview to show some HTML content in iPhone. Now I want to put some action on user events on the phone. I want to trace the tap event done on the screen by the user on that web view.
For this I have added a method
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
in my code.
But the problem is when I click outside the webview it works perfectly. Bt when I tap on the web view, it does not respond. So, please tell me what should I do to acheive tap event trace on that particular web view.
Help me out.
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
if ([[url lastPathComponent] isEqual:#"testmessage"]) {
NSLog(#"Nya");
return NO;
}
return YES;
}
HTML
<a href='testmessage'>Test</a>
or
<script>
function callObjc(){
document.location = 'testmessage';
}
</script>
<a onclick='callObjc();'>Test</a>

iPad - find the true height of a UIWebView

I work for a media company, and in our iPad application we're upgrading our content so it looks better. Previously, we used a UILabel to display the contents of our posts. I used this to get the actual height of my UILabel:
CGSize expectedSize = [label.text sizeWithFont:label.font
constrainedToSize:maximumLabelSize lineBreakMode:label.lineBreakMode];
However, we changed our posts' content to HTML, so I'm using a UIWebView. Is there a way to find the true height of the UIWebView, like I do with the UILabel?
Unlike with a plain string, you'll probably only be able to get the height once the web view finishes rendering. Here's how you can do it in a web view delegate method:
- (void)webViewDidFinishLoad:(UIWebView *)webview
{
NSString *heightString = [webview stringByEvaluatingJavaScriptFromString:
#"document.body.clientHeight"];
int height = [heightString intValue];
...
}

Resources