将参数附加到GWT中的当前URL(Append Parameters to my current URL in GWT)

编程入门 行业动态 更新时间:2024-10-05 07:22:12
参数附加到GWT中的当前URL(Append Parameters to my current URL in GWT)

我在我的应用程序上实现了一个jQuery小部件。 我希望在加载时,小部件启动,并使我必须使用一个参数调用我的URL。

所以,就像这个MYURL /?param = value

我现在这样做:

Window.Location.replace(GWT.getHostPageBaseURL()+"?param=value");

并且工作正常,问题是重新加载应用程序。

有没有办法在不刷新我的网页的情况下执行此操作?

谢谢!

Im implementing a jQuery widget on my app. I want that on load, the widget starts, and to make this i have to call my url with one parameter.

So, it would be like this MYURL/?param=value

Im doing this right now:

Window.Location.replace(GWT.getHostPageBaseURL()+"?param=value");

And works fine, the problem is that reloads the app.

Is there a way to do this without refreshing my webpage?

Thank!

最满意答案

为了不重新加载页面,您必须仅修改散列片段而不是查询字符串。

Window.Location.replace(
   Window.Location.getPath() + Window.Location.getQueryString() +"#whatever");
 

但是,在大多数浏览器中,都有一种名为pushState的新机制,因此您可以在不重新加载页面的情况下将URL更改为任何值。 GWT还没有任何包装器,但您可以通过JSNI使用它,或者,如果您希望使用以下代码将gwtquery添加到项目中:

import static com.google.gwt.query.client.GQuery.*;

Properties history = JsUtils.prop(window, "history");
JsUtils.runJavascriptFunction(history, 
          "pushState", null, null, "whatever.html?foo=true");
 

仅供参考,新的gwtproject网站在浏览菜单时使用此机制和gwtquery。 源代码是gwt git 。

In order not to reload the page, you have to modify just the hash fragment instead of the query string.

Window.Location.replace(
   Window.Location.getPath() + Window.Location.getQueryString() +"#whatever");
 

In most browsers, though, there is a new mechanism called pushState so as you can change the url to whatever value without reloading the page. GWT does not have any wrapper for this yet, but you can use it through JSNI or, if you prefer to add gwtquery to your project, using this code:

import static com.google.gwt.query.client.GQuery.*;

Properties history = JsUtils.prop(window, "history");
JsUtils.runJavascriptFunction(history, 
          "pushState", null, null, "whatever.html?foo=true");
 

FYI, the new gwtproject web site is using this mechanism and gwtquery when navigating through the menu. The source code is in gwt git.

更多推荐

本文发布于:2023-08-07 13:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464082.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   GWT   URL   current   Parameters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!