0

In my app I load a site that uses ad banners and HTML refresh tags.

Every minute (or however long the refresh HTML tag is set) the app goes out to the network to reloads the iframe banner ad on the website (even if it is hidden)

Is there a way to get webView to ignore these?

I tried stoploading and other things in webViewDidFinishLoading, but it still is responding to the HTML refreshes.

Any tips or ideas?

4

2 回答 2

0

I think what he is saying is that you should add this to your code :

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navType
{
    NSURL *pURL = [request URL];
    NSString *pString = [pURL absoluteString];

    // some test on pString, which is now your basic URL to decide if you want to do the load or not
    if ( some test )
        return TRUE;
    else
        return FALSE;
}

or something similar to that....

I had to do something like this recently, as the UIWebView does not stop loading after the view it is on disappears in my navigation heirarchy, caused mysterious crashes sometime later when the refresh occurs, took me a while to hunt it down actually ....

于 2011-07-07T19:42:54.533 回答
0

难道是涉及的网页上有javascript,并且正在加载数据?您可以在加载页面后立即尝试相应地修补 javascript 代码(我认为,有一种方法可以在加载的页面中执行您自己的 javascript,因此您可以注入自己的 js 代码来修改加载的页面,也许禁用横幅代码或删除其整个 div 段)。

当页面跟随链接或加载额外的图片等时,是否有另一个委托函数被调用?不确定,我已经很长时间接触了 webView。也许您必须过滤那里加载的横幅图片。

事实上,看看 UIWebViewDelegate - 有 webView:shouldStartLoadWithRequest:navigationType: 你有没有实现它来看看你是否可以过滤那里的横幅加载?

于 2011-05-17T09:40:12.087 回答