2

I just started to develop with xCode because i need a WebView container for a website. It works so far but i can't logout on the website because there is (in a web browser) a popup window asking if i was sure to logout. I guess it is creates with javascript.

In the Web View settings there is a checkbox labeled "allow popups" but in my app no popup appears after the click.

I've searched for two hours and didn't find something similar related to my problem.

Paul Geisler
  • 715
  • 1
  • 6
  • 23

1 Answers1

4

It was a confirm() function of javascript.

I got it to work with:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [webView setUIDelegate:self]; // <------- This is an important part!!!
    [[webView preferences] setJavaScriptEnabled:YES];
    [[webView preferences] setJavaScriptCanOpenWindowsAutomatically:YES];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:homeURLString]]];
}

and

- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {

    NSInteger result = NSRunInformationalAlertPanel(NSLocalizedString(@"JavaScript", @""),  // title
                                                    message,                // message
                                                    NSLocalizedString(@"OK", @""),      // default button
                                                    NSLocalizedString(@"Cancel", @""),    // alt button
                                                    nil);
    return NSAlertDefaultReturn == result;  
}

More Info here and here.

Community
  • 1
  • 1
Paul Geisler
  • 715
  • 1
  • 6
  • 23