Forum Moderators: open

Message Too Old, No Replies

Javascript to display text based on an off-site document

Hmmm... is this possible?

         

trillianjedi

1:52 pm on Jul 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's what I have on one site. A database of nodes (up to 500) of which maybe a hundred or so are online at any given moment.

These widget "nodes" are maintained by users of my site. A few of these users (a mounting number) are producing their own websites with information about their node. We're currently linking to their info site on our page of online users, so viewers can click on their node and go to the users website to get some info about it.

Hope that all makes sense.

What I would like to do is to produce a little javascript code that these node owners can copy and paste into their site to display whether their node is online or not on their own site.

So I need to do a little lookup on something residing on our server (could be a PHP script that returns a 1 or 0 depending on if it's online or not or I could custom code something).

The javascript in the users page would then display "I'm online" or "I'm not online" depending on the result.

Most of these users are creating their websites on their free ISP webspace, so CGI, PHP or anything else server-side is not going to be possible. Hence I'm thinking about javascript.

I guess it would be a little like a page hit-counter lookup?

Is this possible? I could easily write an app to site on the linux box that simply writes out a text file every five minutes with the online users, something like:-

BOB
PETE
JO

etc. So if they're not on the list, the "offline" message gets displayed, if they are in the list the "online" message gets displayed.

Or any other way that makes it easy from a javascript point of view.

Thanks,

TJ

ajkimoto

5:55 pm on Jul 9, 2004 (gmt 0)

10+ Year Member



trillianjedi,

One solution would be to host, as you suggested, a node-lookup page on your site to let the user page know whether or not the node is active.

If you design this node-lookup page to that it outputs a link, you could have each user set up an iframe on their page, the source of which would be your node-lookup page.

Put something like this in each user site page where nodeid would be customized to equal their nodeid:

<iframe id="myframe" frameborder="0" scrolling="no" src="http://yourdomain.com/node-lookup.htm?nodeid=52"></iframe>

Then design your node-lookup page to process the nodeid parameter and output a link like:

<a href="nodepage52.htm">Node is active</a>

if the node is active or a span like:

<span>Node is inactive</span>

if the node is active.

In either event, the visitor to the user site will see the appropriate html.

A more elegant solution is to use a hidden iframe on each user site whose source would be the node-lookup page. The node lookup page could then call a function on the user page to display the node status. However, since the user web pages are on their own isp sites, this will not work because the browser will not allow you to access the iframe DOM across domains.

Hope this helps,

ajkimoto

trillianjedi

8:33 pm on Jul 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the suggestion and it's a possibility.

I can't help thinking that there must be a more elegant solution however.

How do the counter-scripts work that access a value from a source which is off-site, then display it on a users page?

Thanks,

TJ

thomas858

9:48 pm on Jul 9, 2004 (gmt 0)

10+ Year Member



A pixel gif, with javascript, should do the trick:

<img src="http://www.blabla.com/path/to/pixel.gif" onload="alert('done')">

trillianjedi

1:47 pm on Jul 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Thomas,

I'm not sure I follow that?

It just seems to me to execute "OnLoad" if the pixel.gif exists?

TJ

thomas858

6:57 pm on Jul 10, 2004 (gmt 0)

10+ Year Member



Hi TJ,

> It just seems to me to execute "OnLoad" if the pixel.gif exists?

The tests I have done point in that direction... and if the pixel doesn't exist you get an error.

Nevertheless the proof of concept is incomplete... it follows a more complete one:

<img src="http://www.blabla.com/path/to/Bob's-pixel.gif" onload="alert('online message')" onerror="alert('offline message')">

It's a little tweak of ajkimoto's solution. You need to create a pixel for each online node (and erase the pixels corresponding to the offline nodes). Then you can use an hidden iframe which url points to a document on your user's website, containing the previous javascript code (or whatever you fancy), that way there aren't javascript cross domains problems, because only the images are offsite.

BTW, why don't you simply display an online / offline image à la ICQ for instance? It will work even if javascript is disabled...

trillianjedi

1:54 pm on Jul 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's what I thought Thomas - but it means having 500 plus .gifs which is a really messy way of doing it.

If that's the only way in javascript then I'll custom write an app to run server side and update a database I think.

Thanks anyway,

TJ