0

Hello I have some problems with this script, It shows breadcrumbs but it shows the whole filename with file extension and php parameters

Here is an exemple: Vous êtes ici: Accueil » intranet » index.php#regions

                <script>
                var danielacton = danielacton || {};

                danielacton.insertCrumbs = function() {
                    var regex = /([^:]+:\/\/[^\/]+\/)(.*)/g;
                    var match = regex.exec(document.location.href);
                    var div = document.getElementById('breadcrumb');

                    var aPref = '<a href="';
                    var aBefore = '">';
                    var aAfter = '</a>';

                    var txt = 'You are here: <a href="/">Home</a>';
                    var baseUrl = match[1];
                    var subUrl = '';
                    var components = match[2].split('/');

                    for (var i = 0; i < components.length; i++) {
                        if (components[i].length > 0) {
                            if (!(/\.html(#)?$/.test(document.location.href))) {
                                subUrl = subUrl + components[i]  + '/';
                                txt = txt + '&nbsp;&raquo;&nbsp;'  + aPref +
                                    baseUrl + subUrl + aBefore +
                                    components[i].replace(/-/g, ' ') + aAfter;
                            }
                        }
                    }

                    div.innerHTML = txt;
                }

            </script>
            <div id="breadcrumb">
                <script type="text/javascript">danielacton.insertCrumbs();</script>
            </div>

That is the whole thing

Jason P
  • 26,984
  • 3
  • 31
  • 45
Cedricle
  • 95
  • 1
  • 5

1 Answers1

0

Do a simple string replace

txt = txt.replace('.php', '');
div.innerHTML = txt;

Fiddle

ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49
  • And keep "#regions" and `?querystrings=pleaseno`? I think this is not the expected behavior. – Edgar Griñant Feb 13 '14 at 17:28
  • Valid point. I didn't take that into consideration. I took "I want to hide the files extensions in my breadcrumbs" as the file type (ie. `.php`). Granted I didn't take into account "and php parameters" – ʰᵈˑ Feb 13 '14 at 17:30