【问题标题】:webView JavaFX Redirect A Certain URL When AccessedwebView JavaFX 访问时重定向某个 URL
【发布时间】:2018-07-29 02:04:25
【问题描述】:

我正在使用 javaFX webView 如何将某个 URL 重定向到其他 URL。

示例:-

if user access 
example.com/pathabc
redirect it to
example.com/pathxyz

谢谢。

编辑:-

假设我加载了 example.com(我无法更改,我必须加载 example.com)

example.com 页面有一个指向 example.com/pathabc 的链接,当用户点击它时可以访问。

但我不想让用户访问 example.com/pathabc,所以我想重定向它 example.com/pathxyz

请告诉我如何重定向它。

【问题讨论】:

  • 不清楚你在问什么。对于 Web 视图,无论如何您都必须显式调用 load(...) 才能加载 URL。所以不要加载你不想加载的 URL。
  • @James_D 我已经更新了我希望现在可以正确理解的问题。感谢您的宝贵时间。

标签: java javafx webview webengine


【解决方案1】:

您可以向locationProperty 添加一个侦听器,并在新位置与您要重定向的 URL 匹配时重定向它。

例如

webEngine.locationProperty().addListener((obs, oldLocation, newLocation) -> {
    if (newLocation != null && newLocation.endsWith("example.com/pathabc")) {
        webEngine.load("http://example.com/pathxyz");
    }
});

您可能需要细化匹配 URL 等的标准,但这应该会给您基本的想法。

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2020-01-17
    • 1970-01-01
    • 2017-03-20
    • 2019-01-15
    • 2011-06-25
    • 1970-01-01
    • 2011-10-24
    相关资源
    最近更新 更多