【问题标题】:Delphi TWebBrowser.GoBack: How to handle redirectsDelphi TWebBrowser.GoBack:如何处理重定向
【发布时间】:2016-01-30 16:51:00
【问题描述】:

关于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 你可以设置 Cancel:=false; - 中止当前导航 .` if (pos('news.google.com/news/url',url)>0) then begin Cancel:=false; goback + 1个网址`结束。如果对我的回答有帮助,请投票?我会很高兴:)

标签: delphi twebbrowser


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    把一些代码放到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;
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2018-06-13
        • 2019-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多