rambodrahmani
rambodrahmani

Reputation: 99

Webkit WebView not working

I'm using a Webkit WebView in my app but it actually doesn't work. I mean the page loads but when I click a link on the page nothing happens.

This is my webpage: http://www.beginninghtml.altervista.org

And this is my code:

in my AppDelegate.h:

@property (assign) IBOutlet WebView *webView;

in my AppDelegate.m:

-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
     NSURL *url = [[NSURL alloc] initWithString:@"http://www.beginninghtml.altervista.org"];
     NSURLRequest *req = [[NSURLRequest alloc] initWithURL:url];
    [[_webView mainFrame] loadRequest:req];
}

It correctly loads the page but when I click on the links on the page just nothing happens. Anyone who can help me?

Upvotes: 1

Views: 1196

Answers (2)

rambodrahmani
rambodrahmani

Reputation: 99

Finally I used the following code to open in the Cocoa Webview a link that requires to open a new window:

Set the policyDelegate for you WebView and then implement this code in it:

-(void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id<WebPolicyDecisionListener>)listener
{
    [listener ignore];
    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[request URL]];
    [[_webView mainFrame] loadRequest:req];
}

Upvotes: 1

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

I noticed some of your links request to open new windows rather than opening the page in the current window as usual. It's up to you to Handle New Window Requests. The section I linked to specifically mentions "nothing happens" if such a link is clicked without handling the request as the web view's UI delegate.

Upvotes: 2

Related Questions