cancel load page in javascript
<p>I define a link &lt;a href="http://www.example.com"&gt;Hello&lt;/a&gt;.when i click this link javascript should check the link is exist/valid.if true,the page should be load or the page should resirect to another page.i am using javascript ajax to check the page exist/not.i am using the condition xmlhttp.status == 200.But it is not working.here is the code:</p>

<pre><code>function check(url){
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange=function(){

        if(xmlHttp.readyState==4){
            if (xmlHttp.status==200) 
            {
                alert("Page  Available");
            }
            else 
            {
                window.location.href= "http://www.hello.com";
            }
        }
    }

    xmlHttp.send(null);
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;a href="http://www.example.com" onclick="check(this)"&gt;Click this Link&lt;/a&gt;
</code></pre>

<p>here xmlHttp.status==200 is not working.can anyone help me?</p>
