Well, i'm currently developping a Google Chrome extension and i need to fetch all the DNS and 404 error to make a redirection. The problem is simply that i really don't see how it's possible...
If it's a domain error i want to fetch the domain name and for a 404 error i want to fetch the name page.
Example :
Bad Domain : http://www.justforthetest.com/ => Fetch justforthetest
404 Error : http://www.valeriemates.com/professinal.html => Fetch professinal
Hope someone could p开发者_如何学编程rovide me some helps... Thanks in advance !
Well, the most I was able to do is to send a new XHR request to this URL and check returned status. For wrong domains status seems to be 0
, for 404 pages it is 404
.
background.html
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.status == "loading") {
var xhr = new XMLHttpRequest();
xhr.open("GET", tab.url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if(xhr.status == 0) {
console.log("wrong domain:", tab.url);
} else if(xhr.status == 404) {
console.log("404 page:", tab.url);
} else if(xhr.status == 200) {
console.log("regular page:", tab.url);
}
}
}
xhr.send();
}
});
精彩评论