Wkwebview - 最后访问的屏幕 [英] Wkwebview - last visited screen

查看:22
本文介绍了Wkwebview - 最后访问的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 wkwebview,我将在选项卡之间切换以加载不同的 url,比如 URLl1、url 2 和 URL 3.

I have a single wkwebview which I will switch between tabs to load different urls say, URLl1 , url 2 and URL 3.

考虑场景:

  1. 在 URL 1 的第一个选项卡中,单击链接或执行某些操作并转到 URL 2 的第二个选项卡.

  1. In the first tab with URL 1, Click on the link or do something and go to second tab with URL 2.

当返回到 URL 1 的第一个选项卡时,我需要完全从我离开的地方加载网页.

When coming back to the first tab with URL 1,I need to load the web page exactly from where I left off.

推荐答案

从架构上讲,为每个选项卡分配一个 WKWebView 并在更改选项卡时加载相关 URL 会更有意义.您可以使用以下方法拦截导航:

Architecturally it would make more sense to assign a WKWebView for each tab, and load the relevant URLs when you change tabs. You can intercept the navigation using :

(void)webView:(WKWebView *)webView 
decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction 
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;

并从 WKNavigationAction 对象获取请求.使用该请求在另一个 WKWebView 中加载 url.

And get the request from the WKNavigationAction object. Use the request to load urls in another WKWebView.

让每个 WKWebView 管理自己的历史堆栈.Cookie 也应该在 WKWebView 之间共享,因此使用多个 WKWebView 应该不会出现问题.

Let each WKWebView manage its own history stack. Cookies should be shared across the WKWebViews as well, so using multiple WKWebView should not present a problem.

这篇关于Wkwebview - 最后访问的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆