Delphi TWebBrowser.GoBack: 如何处理重定向

Delphi TWebBrowser.GoBack: How to handle redirects

关于 GoBack 方法,我对 TWebBrowser 有疑问。以下是显示问题的导航历史记录:

[1] htt#://www.google.com/
[2] htt#://news.google.com/nwshp?hl=en&tab=wn
[3] htt#://news.google.com/news/url?sr=1&ct2=us%2F0_0_s_3_1_a&sa=t&usg=AFQjCNGgo-FdxdVP4AVI_HZEV7gS66cjDA&cid=43982236066804&url=http%3A%2F%2Fnews.cnet.com%2F8301-10805_3-57613303-75%2Fmicrosoft-provides-doctors-note-for-sick-xbox-one-gamers%2F&ei=ORaOUvjjJciMgQeGwAE&rt=HOMEPAGE&vm=STANDARD&bvm=section&did=2559730436932654466&ssid=tc
[4] htt#://news.cnet.com/8301-10805_3-57613303-75/microsoft-provides-doctors-note-for-sick-xbox-one-gamers/

到达#4 后,我执行 GoBack 程序。这是出现问题的时候。 GoBack 从历史列表中删除 [4] 并转到 [3],不幸的是重新加载 [4],这有效地取消了 GoBack 请求。

我想要的是允许 [3] 启动 [4] 但阻止其自身保留在堆栈中,以便堆栈看起来像这样:

[1] htt#://www.google.com/
[2] htt#://news.google.com/nwshp?hl=en&tab=wn
[3] htt#://news.cnet.com/8301-10805_3-57613303-75/microsoft-provides-doctors-note-for-sick-xbox-one-gamers/

我该怎么做?

检查 twebbrowser.onbeforenavigate2 事件。它在浏览器加载新资源之前被调用。您可以使用它来取消或重定向请求。

将一些代码添加到 twebbrowser.onbeforenavigate2 事件或 state change 或其他查看每个 mening

 if (pos('news.google.com/news/url',url)>0) then 
begin 
Cancel:=false; //see it abort curent navigation
//go back +1 pages
end;

TWebbrowser.OnBeforeNavigate2 不适用于服务器端重定向!