1

I have a app with storyboard and navigationViewController. On one page, i have a webView object, which contains a webshop. In this view i had to hide the top bar, because i want to use this place for my own html5-bar.

Now my question. Is it possible to trigger the (hidden) backbutton via javascript from webView?

E D I T

I tried this code from the solution-link

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[self navigationController] setNavigationBarHidden:YES animated:YES];
    [self.browser loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.mywebshop.com/mobile/"]]];
}


-(void) webView:(UIWebView *)browser shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ( [[[inRequest URL] scheme] isEqualToString:@"callback"] ) {

        NSLog(@"Catched Succesfull");
    }
    NSLog(@"NOT Catched");
}

But it catches not the event. There is no logging. Did i misunderstood something?

6
  • Are you trying to go back to the previous view? Or have the webview go back to the previous page? Commented Mar 18, 2013 at 22:42
  • Sorry. I have a backButton (in HTML), which should close the IOS webview. Just like clicking the backbutton in IOS. As said before. My header for the View, which contains the webview is hidden. Commented Mar 18, 2013 at 22:47
  • See this answer Commented Mar 18, 2013 at 22:49
  • Did you set your webview's delegate to the class you implemented this method in? Commented Mar 18, 2013 at 23:17
  • i have updateded my code. And in my ".h" i have IbOutlet "@property (retain, nonatomic) IBOutlet UIWebView *browser;" Commented Mar 18, 2013 at 23:25

2 Answers 2

2

You might be interested in history.back() http://www.w3schools.com/jsref/met_his_back.asp

Sign up to request clarification or add additional context in comments.

Comments

1

A popular way (the only way I know) to call back to the UIWebView is to use a custom URI that you intercept. You can see this SO post iOS UIWebView intercept link click

Format the href to something like myapp://closeWebView, then in the delegate method you can listen for that URI, once detected call your native ObjC code to close the UIWebView

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.