JavaScript: Cut URL after nth slash
<p>I have URLs like</p>

<pre><code>http://www.domain.com/dir/dir2/dir3/dir4/#tag
</code></pre>

<p>or</p>

<pre><code>http://www.domain.com/dir/dir2/dir3/dir4
</code></pre>

<p>Now I need to get only the url till dir3 and nothing after that… (or «everything till the sixth slash in the string»)</p>

<pre><code>http://www.domain.com/dir/dir2/dir3/
</code></pre>

<p>How can this be accomblished with JavaScript?</p>
