title: How to make specific JS script work only for certain page
body: <p>How to make script for specific page, checking existing cookies and if exists redirecting to specified page? So far I have something like this, but it keeps triggering the function on every page for some reason( just to clarify I use jQueryMobile):</p>
  
  <pre><code>$(document).on('pageinit',function(){
    jQuery(function($){
      if ($('body#home').length){
        if($.cookie('usr') &amp;&amp; $.cookie('psw')){
          $.mobile.changePage("http://imes.**********.com/userpanel.php");
        }
      }
    });
  });
  </code></pre>
  
  <p>In future I won't be storing name and password in cookie, I know about security issues of this approach, I will be storing generated key to match user from user cookie, but for now, for stage of testing I use these cookies.</p>