我在我的应用程序上实现了一个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.
更多推荐
发布评论