title: echo Javascript window.location.href not working
body: <p>I have a function which echoes javascript to navigate to a different page. While navigation occurs, the  </p>
  
  <pre><code>echo 'window.location.href="'.$url.'";'; 
  </code></pre>
  
  <p>does not work and simply prints it on the screen.</p>
  
  <pre><code>"window.location.href="./index.php";
  </code></pre>
  
  <p>I use my function this way: <code>redirect("./index.php");</code></p>
  
  <p>My php function is as follows</p>
  
  <pre><code>  function redirect($url)
     {    
      if (!headers_sent())
      {    
        header('Location: '.$url);
        exit;
      }
     else
      {      
        echo '&lt;script type="text/javascript"&gt;';
        echo 'window.location.href="'.$url.'";';
        echo '&lt;/script&gt;';
        echo '&lt;noscript&gt;';
        echo '&lt;meta http-equiv="refresh" content="0;url='.$url.'" /&gt;';
        echo '&lt;/noscript&gt;'; exit;
     }
  } 
  </code></pre>