-
JAVASCRIPT > connaitre l’URL courante
exemple :
http://site.fr:8080/fr/search?q=URL#search-resultswindow.location.href>http://site.fr:8080/fr/search?q=URL#search-resultswindow.location.protocol>http:window.location.host>mon.site.fr:8080window.location.hostname>mon.site.frwindow.location.port>8080window.location.pathname>/fr/searchwindow.location.search>?q=URLwindow.location.hash>#search-resultswindow.location.origin>http://mon.site.frwindow.location.usernameusername specified before the domain name.window.location.passwordpassword specified before the domain name.En jQuery :
$(location).attr('href');
méthodes
.assign()Loads the resource at the URL provided in parameter..reload()Recharge la page. reload(true) = recharge du serveur, sinon recharge du cache..replace()comme assign() mais pas de possibilité de retour en arrière (pas d’historique)..toString()synonyme à .href, though it can’t be used to modify the value.changer de page
location.assign("http://ma.page.org"); location = "http://ma.page.org";
recharger la page à partir du serveur
location.reload(true);
propriétés de l’adresse
function showLoc() { var Loc = location, aLog = ["Property (Typeof): Value", "location (" + (typeof Loc) + "): " + Loc ]; for (var sProp in Loc){ aLog.push(sProp + " (" + (typeof Loc[sProp]) + "): " + (Loc[sProp] || "n/a")); } alert(aLog.join("\n")); }
envoyer des données
function sendData (sData) { location.search = sData; } // in html: <button onclick="sendData('Some data');">Send data</button>
The current URL with
?Some%20dataappended is sent to the server.