Hii All,
I want to load a new page when following method is called....I am using the following code..
(void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id )listener
{
[[myWebView mainFrame] loadRequest:someRequest];
}
but this method is called multiple times and my application crashes if i use [listener use] instead of loadRequest it works fine but launches the url clicked . but i want to load some other url how is it possible?
You should simply add [listener ignore]
method call.
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id )listener
{
[listener ignore];
[[myWebView mainFrame] loadRequest:someRequest];
}
It's called multiple times as you say, so you have to pay attention to this:[actionInformation valueForKey: @"WebActionNavigationTypeKey"]
That value should be one of the WebNavigationType
enum:WebNavigationTypeLinkClicked,
WebNavigationTypeFormSubmitted,
WebNavigationTypeBackForward,
WebNavigationTypeReload,
WebNavigationTypeFormResubmitted,
WebNavigationTypeOther
You will get WebNavigationTypeLinkClicked
first as a result of a link clicked, and here you can decide whether to load the page clicked or something else.
Immediately after you get WebNavigationTypeOther
which is the page load, and you can ignore it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With