How to check existsence of a link?

M

marss

Cylix said:
As the title, How to do the ckecking in javascript?
Thanks!

var links = document.links;
for(var i = 0; i < links.length; i++)
{
//check here for specific link
//
//Example:
//if (links != null)
//{
// alert("A link exists :)");
// break;
//}
}
 
E

Evertjan.

marss wrote on 01 feb 2007 in comp.lang.javascript:
As the title, How to do the ckecking in javascript?
Thanks!

var links = document.links;
for(var i = 0; i < links.length; i++)
{
//check here for specific link
//
//Example:
//if (links != null)
//{
// alert("A link exists :)");
// break;
//}
}


I think that the OP wants to test the existence of a website on line.


Test for an image you know should be there.

<img src=
'http://i.a.cnn.net/cnn/2007/WORLD/europe/02/01/blair.police/t1.blair.ap.jp
g'
onload='alert("cnn found")'
onerror='alert("cnn NOT found")'
 
L

-Lost

Evertjan. said:
marss wrote on 01 feb 2007 in comp.lang.javascript:
As the title, How to do the ckecking in javascript?
Thanks!

var links = document.links;
for(var i = 0; i < links.length; i++)
{
//check here for specific link
//
//Example:
//if (links != null)
//{
// alert("A link exists :)");
// break;
//}
}


I think that the OP wants to test the existence of a website on line.


Test for an image you know should be there.

<img src=
'http://i.a.cnn.net/cnn/2007/WORLD/europe/02/01/blair.police/t1.blair.ap.jp
g'
onload='alert("cnn found")'
onerror='alert("cnn NOT found")'


You kill me the way you format your markup. (Not a bad thing!)

Oh and by the way, JSWorld is not a JavaScript site anymore.

-Lost
 
R

Randy Webb

Evertjan. said the following on 2/1/2007 9:36 AM:

Test for an image you know should be there.

<img src=
'http://i.a.cnn.net/cnn/2007/WORLD/europe/02/01/blair.police/t1.blair.ap.jp
g'
onload='alert("cnn found")'

alert('Image found')
onerror='alert("cnn NOT found")'

alert('Image not found')

The existence of an image doesn't tell you anything else about another
file other than that the server may, or may not, be up and running. Try
setting the img src to the file you want to check for.....
 
L

-Lost

Randy Webb said:
Evertjan. said the following on 2/1/2007 9:36 AM:



alert('Image found')


alert('Image not found')

The existence of an image doesn't tell you anything else about another file other than
that the server may, or may not, be up and running. Try setting the img src to the file
you want to check for.....

"the file you want to check for", whether it is an image or not?

-Lost
 
E

Evertjan.

Randy Webb wrote on 02 feb 2007 in comp.lang.javascript:
Evertjan. said the following on 2/1/2007 9:36 AM:



alert('Image found')


alert('Image not found')

The existence of an image doesn't tell you anything else about another
file other than that the server may, or may not, be up and running.
Try setting the img src to the file you want to check for.....

True.
 
E

Evertjan.

Randy Webb wrote on 02 feb 2007 in comp.lang.javascript:
-Lost said the following on 2/1/2007 6:59 PM:

Ayup. Any file at all.

Then the xmlhttp way, perhaps testing only for the header,
would be my first choice.
 
E

Evertjan.

dd wrote on 02 feb 2007 in comp.lang.javascript:
Except for the cross-domain problems of doing that :-(

Do it serverside, with jscript, clientside part being:

<a href='/testIt/testTheSiteFirst.asp?href=http://cnn.com/'>cnn</a>

either server.transfer-ing to notfound.asp
or response.redirect-ing to cnn.com
 
L

-Lost

Evertjan. said:
dd wrote on 02 feb 2007 in comp.lang.javascript:


Do it serverside, with jscript, clientside part being:

<a href='/testIt/testTheSiteFirst.asp?href=http://cnn.com/'>cnn</a>

either server.transfer-ing to notfound.asp
or response.redirect-ing to cnn.com

Um... so we went from client-side to server-side?

Your original check, allowing for Randy's suggestion is still the viable option.

-Lost
 
R

Randy Webb

-Lost said the following on 2/2/2007 4:53 AM:
Um... so we went from client-side to server-side?

Your original check, allowing for Randy's suggestion is still the viable option.

No, the server is the most viable option. If a user has JS disabled or
doesn't have it at all then the client side aspect is broken. But, if I
wanted to verify the link then I would check it on the server and if the
URL didn't exist - don't output the link to start with. No client side
scripting at all.
 
E

Evertjan.

Randy Webb wrote on 02 feb 2007 in comp.lang.javascript:
No, the server is the most viable option. If a user has JS disabled or
doesn't have it at all then the client side aspect is broken. But, if
I wanted to verify the link then I would check it on the server and if
the URL didn't exist - don't output the link to start with. No client
side scripting at all.

True, but reading aviable for viable,
server side scripting is not aviable for all,
though it should be at this time and age.
 
D

dd

server side scripting is not aviable for all,
though it should be at this time and age.

Of course the scum of the earth being what they are though,
they'd build pages that harvest IP addresses and use it for
evil doing :(

~dd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top