如何阻止 IOS 应用程序响应 UIWebView 中的 HTML 刷新

发布于 2024-11-08 12:25:24 字数 231 浏览 4 评论 0原文

在我的应用程序中,我加载了一个使用广告横幅和 HTML 刷新标签的网站。

每隔一分钟(或者无论刷新 HTML 标记设置多久),应用程序都会进入网络以重新加载网站上的 iframe 横幅广告(即使它是隐藏的)

是否有办法让 webView 忽略这些?

我尝试了 webViewDidFinishLoading 中的停止加载和其他操作,但它仍然响应 HTML 刷新。

有什么建议或想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆之渊 2024-11-15 12:25:24

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

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

事实上,看看 UIWebViewDelegate - 有 webView:shouldStartLoadWithRequest:navigationType:
您是否已实现该功能以查看是否可以过滤那里加载的横幅?

Could it be that there is javascript on the webpage involved, and that is loading the data? You could try patching the javascript code accordingly, right after having loaded the page (there's a method to execute your own javascript in a loaded page, I think, and so you could inject your own js code that modified the loaded page, maybe disable the banner code or remove its entire div segment).

And isn't there another delegate function that gets called when the page follows a link or loads extra pictures etc? Not sure, been a long time I've touched the webView. Maybe you have to filter the banner picture loading there.

In fact, look at UIWebViewDelegate - there's webView:shouldStartLoadWithRequest:navigationType:
Have you implemented that to see if you can filter the banner loading there?

甜是你 2024-11-15 12:25:24

我认为他的意思是你应该将这个添加到你的代码中:

-(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;
}

或者类似的东西......

我最近不得不做这样的事情,因为 UIWebView 在它所在的视图消失在我的视图中后不会停止加载导航层次结构,在刷新发生后的某个时间引起了神秘的崩溃,实际上花了我一段时间才找到它......

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 ....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文