Re: Check deadlink
From: Martin Honnen (mahotrash_at_yahoo.de)
Date: 01/23/05
- Next message: Martin Honnen: "Re: Please Help!Error loading Microsoft ActiveX Media Player"
- Previous message: Pola: "Please Help!Error loading Microsoft ActiveX Media Player"
- In reply to: Theewara Vorakosit: "Check deadlink"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 23 Jan 2005 16:01:09 +0100
Theewara Vorakosit wrote:
> How can I check whether a url is deadlink using Jscript/Javascript in IE
> before load it?
With IE/Win (5 and later) you can use the XMLHTTP request object and for
instance make a HEAD request and check the response status e.g.
function getHTTPStatus (url) {
var httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
httpRequest.open('HEAD', url, false);
httpRequest.send(null);
return httpRequest.status;
}
var httpStatus1 = getHTTPStatus('whatever.html');
If the page is not found the status code 404 is sent e.g. you could then
check
if (httpStatus1 == 404) {
// handle missing page
}
But HTTP knows a lot of status codes and you will need to decide what
you regard as missing and not, the codes are documented here:
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10>
And in general a script in a page loaded from http://example.com/ is
only allowed to connect back to that server so you can check
http://example.com/whatever.html and other URLs on that server but not
http://example.org/ or other hosts unless you change the IE settings.
-- Martin Honnen http://JavaScript.FAQTs.com/
- Next message: Martin Honnen: "Re: Please Help!Error loading Microsoft ActiveX Media Player"
- Previous message: Pola: "Please Help!Error loading Microsoft ActiveX Media Player"
- In reply to: Theewara Vorakosit: "Check deadlink"
- Messages sorted by: [ date ] [ thread ]