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?

mr_app
  • 1,292
  • 2
  • 16
  • 37
  • Are you trying to go back to the previous view? Or have the webview go back to the previous page? – Mark Parnell Mar 18 '13 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. – mr_app Mar 18 '13 at 22:47
  • See [this answer](http://stackoverflow.com/questions/2873899/javascript-in-uiwebview-callback-to-c-objective-c) – Mark Parnell Mar 18 '13 at 22:49
  • Did you set your webview's delegate to the class you implemented this method in? – Chris Wagner Mar 18 '13 at 23:17
  • i have updateded my code. And in my ".h" i have IbOutlet "@property (retain, nonatomic) IBOutlet UIWebView *browser;" – mr_app Mar 18 '13 at 23:25
  • `UIWebView` has a delegate property and you must set it to the class that implements the delegate methods. – Chris Wagner Mar 19 '13 at 05:18

2 Answers2

2

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

Nick Andriopoulos
  • 10,313
  • 6
  • 32
  • 56
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

Community
  • 1
  • 1
Chris Wagner
  • 20,773
  • 8
  • 74
  • 95