Forum Moderators: open
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
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
> 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...