Ouvrir une nouvelle page ou rediriger vers une URL différente dans GWT
Un simple exemple de fonction JSNI pour demander à votre application GWT de rediriger ou d'ouvrir une URL différente.
/** * Redirect to URL, changing by the windows.location * @param url The new URL who remplace the current like http://www.gwt.com/ */ public static native void windowLocation(String url)/*-{ $wnd.location = url; }-*/; /** * Open new (tab) browser to URL, open with window.open() * @param url The new URL to open like http://www.gwt.com/ */ public static native void windowOpen(String url)/*-{ $wnd.open(url); }-*/; /** * Redirige la page en cours vers la nouvelle URL * @param url L'url qui remplacera l'actuelle */ public static void pageRediriger(String url) { windowLocation(url); } /** * Ouvre dans le navigateur, une nouvelle page ou onglet a destination de URL * @param url L'url a ouvrir dans un nouvel onglet ou un nouveau navigateur */ public static void pageOuvrir(String url) { windowOpen(url); }
Exemple d'appel :
pageRediriger("http://www.placeoweb.com/"); pageOuvrir("http://dotclear.placeoweb.com/");
Problématique : comment ouvrir une nouvelle page dans un onglet tel que le "clik molette" sur un lien (tout en gardant le focus sur la page principale source) ?
- Window.open() in new tab without focus
- Open new Page on new Browser (tab) application ? How to open new window in new tab without focus ? (pop-up under)
Références
- JSNI
- open(url, name, features)
- developer.mozilla.org : window.open window.open
- selfhtml.org
- toutjavascript.com