Alors, j'étais déconner avec cette Dynamic Breadcrumbs écriture, et suis tombé sur un problème où si le nom du répertoire a un espace, puis% 20 est ajouté au fil d'ariane réelle visible. Serait-ce être supprimé avec l'decodeURI() Fonction ou est-il une meilleure façon?Existe-t-il un moyen de supprimer% 20 du fil d'Ariane créé dynamiquement?
est ici les js:
var crumbsep = " • ";
var precrumb = "<span class=\"crumb\">";
var postcrumb = "</span>";
var sectionsep = "/";
var rootpath = "/"; // Use "/" for root of domain.
var rootname = "Home";
var ucfirst = 1; // if set to 1, makes "directory" default to "Directory"
var objurl = new Object;
// Grab the page's url and break it up into directory pieces
var pageurl = (new String(document.location));
var protocol = pageurl.substring(0, pageurl.indexOf("//") + 2);
pageurl = pageurl.replace(protocol, ""); // remove protocol from pageurl
var rooturl = pageurl.substring(0, pageurl.indexOf(rootpath) + rootpath.length); // find rooturl
if (rooturl.charAt(rooturl.length - 1) == "/") //remove trailing slash
{
rooturl = rooturl.substring(0, rooturl.length - 1);
}
pageurl = pageurl.replace(rooturl, ""); // remove rooturl from pageurl
if (pageurl.charAt(0) == '/') // remove beginning slash
{
pageurl = pageurl.substring(1, pageurl.length);
}
var page_ar = pageurl.split(sectionsep);
var currenturl = protocol + rooturl;
var allbread = precrumb + "<a href=\"" + currenturl + "\">" + rootname + "</a>" + postcrumb; // start with root
for (i=0; i < page_ar.length-1; i++)
{
var displayname = "";
currenturl += "/" + page_ar[i];
if (objurl[page_ar[i]])
{
displayname = objurl[page_ar[i]];
}
else
{
if (ucfirst == 1)
{
displayname = page_ar[i].charAt(0).toUpperCase() + page_ar[i].substring(1);
}
else
{
displayname = page_ar[i];
}
}
if (i < page_ar.length -2)
{
allbread += precrumb + crumbsep + "<a href=\"" + currenturl + "\">" + displayname + "</a>" + postcrumb;
}
else
{
allbread += crumbsep + displayname;
}
}
document.write(allbread);
Si decodeURI() devait être utilisée, où serait-il aller exactement? En outre, plus aucun rapport, y aurait-il une option que vous pouvez ajouter au code ci-dessus qui rendrait la page réelle à l'intérieur du répertoire inclus dans les miettes de pain que le dernier élément au lieu du dernier répertoire? Pas vraiment important mais je pensais que je demanderais aussi. Merci pour toute contribution!
Merci pour votre entrée Cam et pour les informations supplémentaires concernant l'échappement des caractères html. Bon produit! –