I need to be able to figure out what is the previous page in a UIWebView hierarchy so that I can disable the back button on certain instances. So, to clarify:
我需要能够弄清楚UIWebView层次结构中的上一页是什么,以便我可以在某些实例上禁用后退按钮。所以,澄清一下:
User is on page A - clicks on link
User is now on page B - clicks on link
User is now on page C - clicks on the **back** button
User is now on page B
I need to be able to know that "previous" page from page B is page A. The method I'm using right now unfortunately only figures out the previous page the user was in in general. So in the situation above, it thinks the previous navigated page is page C.
我需要知道页面B中的“上一页”页面是页面A.我现在正在使用的方法很遗憾只能找出用户所在的上一页。所以在上面的情况中,它认为以前的导航页面是页面C.
Any help would be appreciated! :)
任何帮助,将不胜感激! :)
2 个解决方案
#1
1
Each time the user clicks on a link and a new page loads, your web view delegate gets a message. So "write down" that information each time! Now you know what "back" means.
每次用户单击链接并加载新页面时,您的Web视图委托都会收到一条消息。所以每次“记下”那些信息!现在你知道“后面”是什么意思了。
Also, you can talk JavaScript to the UIWebView. JavaScript gives you a history
object. A lot of the key functionality in UIWebView is through JavaScript! Apple hasn't bothered to duplicate it in Objective-C properties, because, well, why bother?
此外,您可以将JavaScript与UIWebView对话。 JavaScript为您提供了一个历史对象。 UIWebView中的许多关键功能都是通过JavaScript实现的! Apple没有打算在Objective-C属性中复制它,因为,为什么这么麻烦呢?
#2
0
years later....
多年后....
In researching this same scenario, I came up with a nice solution. Inside webViewDidFinishLoad, check for the property "canGoBack" and hide or unhide your back button accordingly. Thought this was too cool not to share. :)
在研究同样的情况时,我提出了一个很好的解决方案。在webViewDidFinishLoad中,检查属性“canGoBack”并相应地隐藏或取消隐藏您的后退按钮。认为这太酷了不能分享。 :)
if (self.webView.canGoBack)
{
self.backButton.hidden = NO;
}
else
{
self.backButton.hidden = YES;
}
#1
1
Each time the user clicks on a link and a new page loads, your web view delegate gets a message. So "write down" that information each time! Now you know what "back" means.
每次用户单击链接并加载新页面时,您的Web视图委托都会收到一条消息。所以每次“记下”那些信息!现在你知道“后面”是什么意思了。
Also, you can talk JavaScript to the UIWebView. JavaScript gives you a history
object. A lot of the key functionality in UIWebView is through JavaScript! Apple hasn't bothered to duplicate it in Objective-C properties, because, well, why bother?
此外,您可以将JavaScript与UIWebView对话。 JavaScript为您提供了一个历史对象。 UIWebView中的许多关键功能都是通过JavaScript实现的! Apple没有打算在Objective-C属性中复制它,因为,为什么这么麻烦呢?
#2
0
years later....
多年后....
In researching this same scenario, I came up with a nice solution. Inside webViewDidFinishLoad, check for the property "canGoBack" and hide or unhide your back button accordingly. Thought this was too cool not to share. :)
在研究同样的情况时,我提出了一个很好的解决方案。在webViewDidFinishLoad中,检查属性“canGoBack”并相应地隐藏或取消隐藏您的后退按钮。认为这太酷了不能分享。 :)
if (self.webView.canGoBack)
{
self.backButton.hidden = NO;
}
else
{
self.backButton.hidden = YES;
}