Javascript: check if the url is changed or not?
<p>My url format is like : </p>

<pre><code>http://domain.in/home
http://domain.in/books/notes
http://domain.in/books/notes/copy
</code></pre>

<p>I've called a javascript function on window.load to check if the url has changed or not.</p>

<p>If the url has been changed then code is executed else it will return and checks again after 5 sec.</p>

<p>My code is :</p>

<pre><code>window.onload = function(){
   setInterval(function(){
       page_open();
   }, 5000);
};

function page_open(){
    var pages=unescape(location.href);
    pages=pages.substr( pages.lastIndexOf("studysquare.in/") + 15 ); 

    // gives book if url is http://studysquare.in/book
    //alert("pages"+pages+"\n\n  recent"+recent);

    if (pages==recent) {    return;     }
    recent=pages;

    alert("Reached down now the code will execute.");
}
</code></pre>

<p>The problem now is : when the url is like :</p>

<pre><code>http://domain.in/book
</code></pre>

<p>Single level deep, then everything works fine. But when the url is like</p>

<pre><code>http://domain.in/book/copy    or    http://domain.in/book/copy/notes
</code></pre>

<p>Then nothing works.....
Any help to check 3 level deep url  change in javascript every 5 sec ? :)</p>

<p>Hi sorry I forgot to tell that... I've .htaccess file which doesnt allow to navigate the page when any length url after the <code>domain.in/</code> is written.... that means only single page remains open and not affected by the url change...</p>
