/    Sign up×
Community /Pin to ProfileBookmark

how do you check if a link is valid

I saw the command the other day but I can’t recall what it is, like if was to check a link to see if existed or not

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@domiereavronauthorDec 22.2006 — oh nonono

we have list of files that are divided into four links,

so the base linke is www.abc.com/blah for one or it might be under www.cbd.com/blah, what I am looking to do is to be able to search our a file to see if it was put into one of the four directories.
Copy linkTweet thisAlerts:
@domiereavronauthorDec 22.2006 — ironically you gave me the link I wanted your the man, for the xml stuff
Copy linkTweet thisAlerts:
@domiereavronauthorDec 23.2006 — ummm having trouble getting this code to work

var xmlhttp=false;

/*@cc_on @*/

/*@if (@_jscript_version >= 5)

// JScript gives us Conditional compilation, we can cope with old IE versions.

// and security blocked creation of the objects.

try {

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try {

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

} catch (E) {

xmlhttp = false;

}

}

@end @*
/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

try {

xmlhttp = new XMLHttpRequest();

} catch (e) {

xmlhttp=false;

}

}

if (!xmlhttp && window.createRequest) {

try {

xmlhttp = window.createRequest();

} catch (e) {

xmlhttp=false;

}

}

</script>

<script type="text/javascript">


function linkcheck(url) {

xmlhttp.open("HEAD", url,true);

xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4) {


if (xmlhttp.status==200) alert("URL Exists!")

else if (xmlhttp.status==404) alert("URL doesn't exist!")

else alert("Status is "+xmlhttp.status)

}

}

}

</head>

</script>

<body>


<form name="link">

<input type="text" name="reqlink">

<button onClick="linkcheck(document.link.reqlink.value)">test</button>

</form>


</body>

</html>
Copy linkTweet thisAlerts:
@domiereavronauthorDec 23.2006 — figured out my error

correction now it is just telling me the status is 2 regardless of what I am putting in, revised code

<html>

<head>

<script type="text/javascript">

var xmlhttp=false;

/*@cc_on @*/

/*@if (@_jscript_version >= 5)

// JScript gives us Conditional compilation, we can cope with old IE versions.

// and security blocked creation of the objects.

try {

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try {

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

} catch (E) {

xmlhttp = false;

}

}

@end @*
/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

try {

xmlhttp = new XMLHttpRequest();

} catch (e) {

xmlhttp=false;

}

}

if (!xmlhttp && window.createRequest) {

try {

xmlhttp = window.createRequest();

} catch (e) {

xmlhttp=false;

}

}






function linkcheck(url) {

xmlhttp.open("HEAD", url,true);

xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4) {

if (xmlhttp.status==200) alert("URL Exists!")

else if (xmlhttp.status==404) alert("URL doesn't exist!")

else alert("Status is "+xmlhttp.status)

}

}

xmlhttp.send(null)

}


</script>

</head>


<body>


<form name="flink">

<input type="text" name="reqlink">

<button name="test" onClick="linkcheck(document.flink.reqlink)">test</button>

</form>


</body>

</html>
×

Success!

Help @domiereavron spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...