– webView:shouldStartLoadWithRequest:navigationType:In web view Click on the hyperlink trigger ,Is there any way How can I do this?
//WebView will automatically load the hyperlink u need not to do anything out there except.
//Inherit <UIWebViewDelegate> in self;
urwebview.delegate=self;
In self implement delegate method
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
//Its call back receved whenever ur webview is navigated By clicking on hyperlink
}
Related
I'm working to view a local html page inside a WebView and I want to disable going to any external website if the user clicks any button within the page i.e. <a href="www.google.com">
You want to set a policyDelegate for your view. See the docs for WebPolicyDelegate. The specific method you want to implement is:
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id<WebPolicyDecisionListener>)listener
The simplest thing to do is just call [listener ignore] for everything. That will also prevent any back/forward navigation, reloads, or form submits from working. If you want more control, you can look at the actionInformation dictionary and check the type before calling [listener ignore] or [listener use].
I load up a UIWebView in my app which displays html text and a sign out button.
Is it at all possible that when the user taps the html button it can then change the view? ie: it will go back in navigation of the app to the previous view?
Any examples of this being done?
Can this also be done in java for my Android version?
Edit: If I place an event using JS or something on the button can I then use a listener within the app's web view to go back a view?
What you could do is...
When one of your buttons is pressed, it actually attempts to send the user to a new URL (eg, through a href="", or javascript redirect). But, in your app's code you can use UIWebView's delegate methods to intercept the loading of the URL and instead run some app-based code.
Eg.
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *_url = [NSString stringWithFormat:#"%#", request.URL];
if ([_url rangeOfString:#"?signout"].location != NSNotFound) {
[self userRequestsLogout];
return NO;
}
return YES;
}
Don't forget that UIWebView also has;
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
Hopefully this helps.
I have some issues with this UIWebViewDelegate method.
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Issue:
While changing any tab or clicking on any link, this method gets called automatically.
It was working fine for me also, but surprisingly it's not getting called since yesterday. I tried everything, but it's still not working. How can I resolve this?
Check u have done this:
#interface yourViewController : UIViewController <UIWebViewDelegate>
Also check add this line:
yourWebView.delegate = self;
IF you are making webView using xib then connect its delegate to file's owner, or if you are making webView through code then write
myWebView.delegate = self;
I'm trying to make an event which will be called (and will excecute objective-c code on iPhone) when specific button is pressed on a website in webView.
The simple way I think is to listen webView's HTTP requests.
Can I do that?
In your HTML, give the URL a special scheme. In this example, the scheme is perform:
<!-- ontouchstart tells WebKit to send us mouse events on a touch platform so we can use :active -->
<button class="button" ontouchstart="" onclick="window.open('perform:MAX')">MAX</button>
(You could use <a href here or other techniques. This example comes from code where using onclick was useful.)
Set your controller as the delegate of the UIWebView. Then implement this delegate method:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
if ([[url scheme] isEqualToString:#"perform"])
{
// url.resourceSpecifier will be #"MAX" in this example
// Do something with it.
return NO;
}
return YES;
}
I have a webview that displays properly, however the links are entirely inactive. If I try to select a link the selection magnifying glass appears. I've tried overriding
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
but the method will not execute. The class extends UIViewController <UIWebViewDelegate>, and my view is located in a tabbar, but I'm fairly certain everything's connected properly. Any suggestions?
Set the property - Detects link in the UIWebView class to YES.