Location représente l'emplacement pointé par le navigateur.
CompatibilitéDisponibilité
Javascript 1.0 côté client
Adresse URLSynopsisProtocole//Hôte:Port/Chemin#Ancre?Recherche (http://www.laltruiste.com/coursjavascript/index.html#LettreJ)
locationPropriétés
window.location
| Propriété | Description |
|---|---|
| hash | sépcifie un nom d'ancre dans une URL (adresse#Ancre). |
| host | spécifie le nom de domaine de l'hôte ou l'adresse IP du réseau hôte. |
| hostname | indique le nom de domaine du serveur hôte. |
| href | spécifie l'URL complète du lien (HREF). |
| pathname | retourne le chemin d'accès du lien. |
| port | indique le port de communication que le serveur utilise. |
| protocol | spécifie le protocole de l'URL en incluant les deux-points (http:). |
| search | spécifie une requête de recherche (URL?Requête). |
| Méthode | Description |
|---|---|
| reload | force un rechargement du document courant. |
| replace | charge une URL spécifiée au-dessus du document courant. |
<html>
<head>
<script language="javascript">
var cours = ['un.html','deux.html','trois.html'];
var taille = cours.length;
var navigateur = navigator.appName;
var hote = document.location.host;
var localisation = document.location.pathname;
var racine = (hote != '' || navigateur == 'Netscape')
? localisation.split('/') : localisation.split(/&&/);
var condition = racine.length;
var fichier = racine[condition - 1];
var acces = localisation.replace(fichier, '');
document.write('<br>Navigateur : ' + navigateur
+ '<br>localisation : ' + localisation
+ '<br>hôte : ' + hote
+ '<br>fichier : ' + fichier
+ '<br>accès : ' + acces);
function suivant()
{
for (var i = 0; i < taille; i++)
{
var situe = (acces + cours[i]);
if (situe == localisation)
{
if (i != (taille - 1))
{
window.location.replace(cours[i + 1]);
return true;
}
else
{
window.location.replace(cours[0]);
return true;
}
}
}
alert('Le document suivant est invalide'
+ '&nVeuillez en informer le Webmaster !')
window.location.replace(cours[0]);
}
function precedent()
{
for (var i = 0; i < taille; i++)
{
var situe = (acces + cours[i]);
if (situe == localisation)
{
if (i != 0)
{
window.location.replace(cours[i - 1]);
return true;
}
else
{
window.location.replace(cours[taille - 1]);
return true;
}
}
}
alert('Le document précédent est invalide'
+ '&nVeuillez en informer le Webmaster !')
window.location.replace(cours[0]);
}
</script>
</head>
<body>
<a href="javascript:precedent()">Document précédent</a>
<< Première Page >>
<a href="javascript:suivant()">Document suivant</a>
</body>
</html> |
<html>
<head>
<title>Fenêtre principale</title>
</head>
<frameset rows="15%,*">
<frame name="cadre_superieur" src="cadre_superieur.html">
<frameset cols="25%,*">
<frame name="cadre_gauche" src="cadre_gauche.html">
<frame name="cadre_droit" src="cadre_droit.html">
</frameset>
<noframes>
<body>
</body>
</noframes>
</frameset>
</html>
<html>
<head>
<title>Cadre gauche</title>
<script language="Javascript" type="text/javascript">
function chargement(page,cadre) {
parent.frames[cadre].location.href = page;
}
function double_chargement(page1, page2) {
parent.frames["cadre_droit"].location.href = page1;
parent.frames["cadre_superieur"].location.href = page2;
}
</script>
</head>
<body>
<h1>Cadre gauche</h1>
<a href="http://www.laltruiste.com/index.html"
target="cadre_droit">
Lien HTML
</a>
<br>
<a href="Javascript:chargement('http://www.laltruiste.com/contact.html',
'cadre_droit')">
Lien Javascript simple
</a>
<br>
<a href="Javascript:double_chargement('../sommaire.html',
'../../images/interface/bandeau-468x60.gif')">
Lien Javascript double
</a>
</body>
</html>
<html>
<head>
<title>Cadre supérieur</title>
</head>
<body>
<h1>Cadre supérieur</h1>
</body>
</html>
<html>
<head>
<title>Cadre droit</title>
</head>
<body>
<h1>Cadre droit</h1>
</body>
</html> |