get relative URL with javascript
<p>Is there an easy way to get the relative url with javascript? Im trying to use <code>window.location.href</code> but it returns the absolute path.</p>

<p>What im trying to do is this: I have two pages; mobile.html and desktop.html. I want to use ONE javascript-file to detect whether the user is on a mobile or desktop (I know, this is not a very good way to do it..) like this:</p>

<pre><code>var is_mobile = //alot of text from http://detectmobilebrowsers.com/
                //that returns true/false, this works fine

if (is_mobile){

    if (window.location.href != "mobile.html"){
        window.location = "mobile.html";
    }
}

else {
    if (window.location.href != "desktop.html"){
        window.location ="desktop.html";
    }
}
</code></pre>

<p>So the problem with absolute path is that when testing either mobile/desktop.html they both go into infinite loop pagerefresh..</p>
