11 Vote

JavaScript: window.location comme String

Info de Stefan Trost | 01/02/2020 à 13:20

Même si cela semble parfois, window.location n'est pas une string mais un objet. Par conséquent, nous devons convertir window.location en string avant de pouvoir l'utiliser avec des fonctions de string telles que .indexOf().

Pour convertir window.location en string, il existe plusieurs possibilités:

  • var s = window.location.toString();
  • var s = window.location.href;
  • var s = String(window.location);

Après cela, notre variable de string s contient notre URL afin que nous puissions continuer à travailler avec elle.

RépondrePositifNégatif

Sur l’Auteur

AvatarVous pouvez trouver des logiciels de Stefan Trost sur fr.sttmedia.com. Avez-vous besoin d'un logiciel personnalisé selon vos propres besoins? Écrivez-nous: fr.sttmedia.com/contact
Voir Profil

 

Sujets Connexes

VirtualBox: Changer la Date et l'Heure

Tutoriel | 10 Commentaires

CSS: Comment inclure CSS dans HTML

Tutoriel | 0 Commentaires

Avis Important

Veuillez noter: Les contributions publiées sur askingbox.com sont des contributions d’utilisateurs et ne doivent pas remplacer les conseils d’un professionnel. Ils ne sont pas vérifiés par des indépendants et ne reflètent pas nécessairement l’opinion de askingbox.com. Apprendre encore plus.

Participer

Posez votre propre question ou écrivez votre propre article sur askingbox.com. Voici comment.