【问题标题】:Reloading is not consistent in different browsers不同浏览器重载不一致
【发布时间】:2015-01-09 07:09:48
【问题描述】:

我们正在使用 gwt-java 应用程序。在一种情况下,我需要在我的应用程序中重新加载我的浏览器窗口,这就是为什么我想使用无法持续工作的“Window.Location.reload()” 然后我使用强制重新加载在“Chrome”中工作但在 Firefox 和 IE 中不断重新加载窗口(无法正常工作)的应用程序。

Chrome - 版本 40.0.2214.45 beta-m(64 位) 火狐 - 24.0 IE - 11

forceReload():

 private static native void forceReload() /*-{
  $wnd.location.reload(true);
}-*/;

重新加载浏览器窗口的最佳方法是什么?

【问题讨论】:

  • 请更全面地描述您的问题,例如您的代码(有条件?)调用forceReload

标签: java gwt browser jsni


【解决方案1】:

两个选项:

1)Window.Location.reload();

重新加载当前浏览器窗口。所有GWT 状态都将丢失。

2)Window.Location.replace("myUrl");

用新的 URL 替换当前 URL。所有GWT 状态都将丢失。在浏览器的历史记录中,当前 URL 将被新 URL 替换。

另外,window.location.reload(true) 参考here

如下所示

public static native void reload(boolean force) /*-{
  $wnd.location.reload(force);
}-*/;   // by default force reload is false

【讨论】:

  • 谢谢@ankur,但我在使用不同的浏览器时遇到了问题。
  • @User 请发布它适用于哪些浏览器,哪些浏览器不能正常工作,如果需要,请检查浏览器和操作系统的兼容性。
  • @User 你试过用Window.Location.replace("myUrl")
  • 我可以尝试使用 url,但我需要为此构建 url。
  • @User 我希望你得到当前窗口的 url Window.Location.getHref()
【解决方案2】:

您的意思是您只希望您的页面在满足条件时重新加载一次?我编辑了我的答案,看看您是否可以添加一个“虚拟标志”来指示事件/条件以仅加载一次。

if (YourCondition == true && yourConditionFlag  == true){

    yourConditionFlag = false;
    location.reload(true);
}

【讨论】:

  • 是的,但是即使我在 Firefox 和 ie 中遇到上述情况,加载也会永远发生。
  • 如果您提到条件是什么会有所帮助?可能有一些代码,看看编辑后的答案是否能满足您的需求?
  • 这是我们自己的条件,例如: if(existingId.equals(newId) == false) { private static native void forceReload() /*-{ $wnd.location.reload(true); }-*/; }
  • 这很可能无济于事,因为重新加载后所有 GWT(客户端)状态都丢失了。 yourConditionFlag 无法在重新加载后存活。
  • 是否可以将yourConditionFlag 值传递给servlet? Please refer this
猜你喜欢
  • 2014-08-17
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 2011-08-09
  • 1970-01-01
  • 2012-11-05
  • 1970-01-01
  • 2013-06-25
相关资源
最近更新 更多