By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,479 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,479 IT Pros & Developers. It's quick & easy.

How to check existsence of a link?

P: n/a
As the title, How to do the ckecking in javascript?
Thanks!

Feb 1 '07 #1
Share this Question
Share on Google+
14 Replies

P: n/a

Cylix wrote:
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[i] != null)
//{
// alert("A link exists :)");
// break;
//}
}

Feb 1 '07 #2

P: n/a
marss wrote on 01 feb 2007 in comp.lang.javascript:
>
Cylix wrote:
>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[i] != 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")'
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 1 '07 #3

P: n/a
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
marss wrote on 01 feb 2007 in comp.lang.javascript:
>>
Cylix wrote:
>>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[i] != 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
Feb 1 '07 #4

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

<snip>
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.....

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 1 '07 #5

P: n/a
"Randy Webb" <Hi************@aol.comwrote in message
news:Lf********************@telcove.net...
Evertjan. said the following on 2/1/2007 9:36 AM:

<snip>
>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.....
"the file you want to check for", whether it is an image or not?

-Lost
Feb 2 '07 #6

P: n/a
-Lost said the following on 2/1/2007 6:59 PM:
"Randy Webb" <Hi************@aol.comwrote in message
news:Lf********************@telcove.net...
>Evertjan. said the following on 2/1/2007 9:36 AM:

<snip>
>>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.....

"the file you want to check for", whether it is an image or not?
Ayup. Any file at all.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 2 '07 #7

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

<snip>
>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.....
True.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 2 '07 #8

P: n/a
Randy Webb wrote on 02 feb 2007 in comp.lang.javascript:
-Lost said the following on 2/1/2007 6:59 PM:
>"Randy Webb" <Hi************@aol.comwrote in message
news:Lf********************@telcove.net...
>>Evertjan. said the following on 2/1/2007 9:36 AM:

<snip>

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.blai
r.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.....

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

Ayup. Any file at all.
Then the xmlhttp way, perhaps testing only for the header,
would be my first choice.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 2 '07 #9

P: n/a
dd
On Feb 2, 7:58 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Then the xmlhttp way, perhaps testing only for the header,
would be my first choice.
Except for the cross-domain problems of doing that :-(

Feb 2 '07 #10

P: n/a
dd wrote on 02 feb 2007 in comp.lang.javascript:
On Feb 2, 7:58 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>Then the xmlhttp way, perhaps testing only for the header,
would be my first choice.

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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 2 '07 #11

P: n/a
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
dd wrote on 02 feb 2007 in comp.lang.javascript:
>On Feb 2, 7:58 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>>Then the xmlhttp way, perhaps testing only for the header,
would be my first choice.

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
Um... so we went from client-side to server-side?

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

-Lost
Feb 2 '07 #12

P: n/a
-Lost said the following on 2/2/2007 4:53 AM:
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
>dd wrote on 02 feb 2007 in comp.lang.javascript:
>>On Feb 2, 7:58 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Then the xmlhttp way, perhaps testing only for the header,
would be my first choice.
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

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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 2 '07 #13

P: n/a
Randy Webb wrote on 02 feb 2007 in comp.lang.javascript:
>>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.

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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 2 '07 #14

P: n/a
dd
On Feb 2, 4:21 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
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

Feb 3 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.