How can I determine if a 404'd site is in javascript and then redirect the browser to another location

I am trying to write a greasemonkey script for firefox that will check the site upon opening and see if the site is 404'd, and then redirect the user to another location.

thank

+3
source share
3 answers
// ==UserScript==
// @name           Redirect
// @namespace      test
// @include        *
// ==/UserScript==

if (/^about:neterror/.test(document.documentURI))
{
    location.assign(...);
}
+3
source

Make an AJAX request in the URI and check the response code from the returned XHR object for error code 404 (or! = 200).

Do you have access to some kind of JS Framework?

+2
source

" " , URL- .

"" - , , .

- .

-, , URL-.

  • , . checkRemotePage.php
  • checkRemotePage.php
  • /checkRemotePage.php ajax, .

url url, apache mod_proxy

0

Source: https://habr.com/ru/post/1789343/


All Articles