Is there a way to remove %20 from dynamically created breadcrumbs?

So, I was messing around with this [Dynamic Breadcrumbs][1] write-up, and came across an issue where if the directory name has a space in it, then %20 gets added to the actual visible breadcrumb. Would this be removed using the **decodeURI()** function or is there a better way? Here's the js: var crumbsep = " • "; var precrumb = ""; var postcrumb = ""; 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 + "" + rootname + "" + 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 + "" + displayname + "" + postcrumb; } else { allbread += crumbsep + displayname; } } document.write(allbread); If **decodeURI()** was to be used, where exactly would it go? Also, more unrelated, would there be an option you could add to the code above that would make the actual page inside of the directory be included in the breadcrumbs as the last item instead of the last directory? Not real important but thought I would ask as well. Thanks for any input! [1]: http://www.webmonkey.com/2010/02/build_dynamic_breadcrumbs_with_javascript/

以上就是Is there a way to remove %20 from dynamically created breadcrumbs?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏