Test if my page is up using javascript?

B

Bill DeWitt

I want to supply a button on my public web page if I have opened up my
private web page, but disable it or remove it if the private page is shut
down. Is this possible?

In other words, I often have a port open for a chat page and I use
no-ip.com to do a port redirect. When the port is open, I want my public
page to test the port when a user loads the page, and if the port is
available, supply a button to click over to it.

Sort of like the service at http://www.canyouseeme.org/, except I would
provide the ip and port in the code.

Can this be done with Javascript? Thanks for any help.
 
J

Joshie Surber

If both are on the same domain (different subdomains are okay) you
could use a cookie.

If that won't work, your other option (as I see it) is more convoluted.
Have the private page set up a script that polls the server (either
one) every few seconds, with something tagging along on the request to
ID whoever is on the page. You will need something server side to keep
track of the polling, but the JS would be easy: just request a PHP (or
asp, etc) generated image with new Image().src='polling.php'. Set up
something similar on the public page that does likewise, but requests a
differant image. Then if your polling shows that the person IS on your
private page, return a single pixel gif, but return your button
otherwise.
 
B

Bill DeWitt

Hi, Joshie. Thanks for taking the time to respond.

Of course, I don't know or else I wouldn't ask, but that seems a little
complicated. Perhaps I asked the question wrong. I had envisioned something
like...

" if (ping(address)) then hotbutton else greybutton "

....but, of course, in javascript.

I don't think I need constant updating, just a check on loading the page.
 
T

Tom Cole

Bill said:
Hi, Joshie. Thanks for taking the time to respond.

Of course, I don't know or else I wouldn't ask, but that seems a little
complicated. Perhaps I asked the question wrong. I had envisioned something
like...

" if (ping(address)) then hotbutton else greybutton "

Why not have your "sometimes offline" site provide the image for the
button. If your site's not there, then no picture...leaves you with
other things to think about...

or...

Another option is to fire off an XmlHttpRequest to the "sometimes
offline" site and read the status. If you don't get a 200 (or if you do
get a 404 it's up to you) then no show, otherwise, do show...

HTH
 
B

Bill DeWitt

Tom Cole said:
Why not have your "sometimes offline" site provide the image for the
button. If your site's not there, then no picture...leaves you with
other things to think about...

Hmm... I will try this, but I suspect that my "integrated chat/server
software will not allow it.
Another option is to fire off an XmlHttpRequest to the "sometimes
offline" site and read the status. If you don't get a 200 (or if you do
get a 404 it's up to you) then no show, otherwise, do show...

This sounds possible, both that it could work and that I could
accomplish it :cool: Although I have no idea what a "XmlHttpRequest " is...

I will go look it up now, thanks for your response!
 

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
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top