angularjs - How to check webpage is available or not using javascript -
i want make web page request if web page available. have written app using angularjs + javascript. there way determine whether webpage available or not using javascript ?
if page in question on different origin, can't without using server somewhere or relying on other page implementing cross-origin resource sharing , supporting origin, because of same origin policy.
if page in question on same origin, can ajax call query it:
var xhr = new xmlhttprequest(); xhr.open("head", url); xhr.onreadystatechange = function() { if (xhr.readystate == 4) { if (xhr.status == 200) { // worked } else { // didn't } } }; xhr.send();
Comments
Post a Comment