<script> var arr = [ 'location.href=', location.href, '\nlocation.protocol=',location.protocol, '\nlocation.hostname=',location.hostname, '\nlocation.pathname=',location.pathname, '\nlocation.port=', location.port, '\nlocation.hash=', location.hash, '\nlocation.search=', location.search ]; alert( arr.join("") ); </script>
<script> var obj = document.createElement('a'); obj.href = "http://www.example.com/aa/bb.htm?key=val#anchor"; var atg = [ 'obj.href=', obj.href, '\nobj.protocol=',obj.protocol, '\nobj.hostname=',obj.hostname, '\nobj.pathname=',obj.pathname, '\nobj.hash=', obj.hash, '\nobj.port=', obj.port, '\nobj.search=', obj.search ]; alert( atg.join("") ); </script>
<a href='http://www.domain.de/'>http://www.domain.de/</a> <a href='http://www.domain.de/aaa/'>aaa/</a> <a href='http://www.domain.de/aaa/bbb/'>bbb/</a> <a href='http://www.domain.de/aaa/bbb/ccc.htm'>ccc.htm</a> Auf der Seite erscheint sichtbar etwa: http://www.domain.de/ aaa/ bbb/ ccc.htm --------------------- ---- ---- -------
<script> function url2pfad( url ) { var aa, tmp, len, href = [ ], s = "<a href='xxx'>yyy</a>"; aa = url.replace('//','o0OO').split('/'); aa[0] = aa[0].replace('o0OO','//'); tmp = aa.join('/oO0o').split('oO0o'); /*1*/ txt = aa.join('/oO0o').split('oO0o'); len = txt.length; aa = []; /*2*/ for (i = len - 1; i >= 0; i -= 1) { aa.unshift(s.replace('xxx',tmp.join("")).replace('yyy',txt[i])); tmp.pop(); /*3*/ } return aa.join('\n'); } // Testaufruf erfolge etwa so: var s = url2pfad('http://www.domain.de/aaa/bbb/ccc.htm'); document.write( s ); /*4*/ </script>
<a href='http://www.domain.de/'>http://www.domain.de/</a> <a href='http://www.domain.de/aaa/'>aaa/</a> <a href='http://www.domain.de/aaa/bbb/'>bbb/</a> <a href='http://www.domain.de/aaa/bbb/ccc.htm'>ccc.htm</a>