[tpm] [OT] Javascript to watch for certain KW from a web page

Shaun Fryer sfryer at sourcery.ca
Wed Oct 10 07:27:45 PDT 2012

Hi Antonio,

That makes sense. Unfortunately it's a little beyond the scope of a
simple email to provide a complete solution for your situation.
However, you might try something like the following.

You'll need two things. #1. an ajax function of some kind. Given that
you aren't interested in learning JS, I'd recommend using a
cross-browser abstraction library which has an ajax method, such as
jQuery. #2. You'll need a popup dialogue of some kind. There are
plenty to choose from. For the purposes of providing an example, I've
[arbitrarily] chosen the facybox jQuery plugin. I have no direct
experience with it, but the API seems simple enough, so it should work

Add a script tag including the jQuery library, followed by one for the
plugin for your popup ( http://bitbonsai.com/facybox/ ). Now in a
separate script tag below this, add code similar to that below
(modified accordingly).

var nMilliseconds = 60*1000; // frequency of server check in milliseconds
var checkServerStatus = function () {
  $.ajax({ url: "/path/to/your/log/file/script" }).done(function
(jqXHR, textStatus) {
    if (/a regexp matching text in your log file/.test(jqXHR.responseText))
      $.facybox("The text you wish the user to see in the popup dialogue.");
    else setTimeout( checkServerStatus, nMilliseconds );
setTimeout( checkServerStatus, nMilliseconds );

The above is just pseudo-code, but it *should* work with very little
modification, assuming you're using the indicated JS libraries.

Hope this helps.
Shaun Fryer
perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \

On Wed, Oct 10, 2012 at 9:51 AM, Antonio Sun <antoniosun at lavabit.com> wrote:
> Hi, thanks a lot for your offer Shaun.
> That was actually what I thought the solution to be. Now let's forget what I
> said and focus on what I need to accomplish.
> Yes, I totally control the page content. The situation is,
> I am designing a web portal that can launch back-end server side processes.
> The problem is that the process can finish in seconds, or it might need
> hours to finish, depending how much work the process has. So my design is to
> spawn a sub process, and capture all its outputs to a log text file, then
> return immediately to the user, in a web notice page saying, your job is
> queued; here is the log url; please check manually if is finished or not.
> But my all my fellow coworkers said they don't want to check themselves.
> Instead, they want my web portal to check for them. I couldn't think of any
> solution from the server side to capture the end of the sub process, then
> informed the already submitted web notice page. Hence, I'm turning to the
> javascript front-end for solutions. Because I have zero knowledge of
> Javascript, it might not be feasible at all. But I know the best solution is
> that if I can have a desktop notification mechanism just like gmail does,
> that should solve the problem, because my sub process control task does know
> when the sub process ends, and write a specific ending tag to the end of the
> log file, which is what I was planning to watch/search for. Every page of my
> portal does include a standard master template (except the log text file),
> so if I can send a signal at the end of my sub process and capture that by
> the master template, then pop up a javascript window, that will do as well.
> Sorry for the lengthy gibberish, hope that you can figure something out from
> it.
> Thanks
> On Wed, Oct 10, 2012 at 3:01 AM, Shaun Fryer <sfryer at sourcery.ca> wrote:
>> Hi Antonio,
>> I might be able to help you, but first I need to know a bit more
>> detail about what you're trying to do. When you say watch for certain
>> keywords from a webpage, what do you mean exactly? If you mean
>> searching through a static html document looking for a give word or
>> words, that's fairly trivial. However, if you can add javascript to
>> the page in question, then you probably control the page, and
>> therefore should already know it's content. So question is, why would
>> you need front-end code in JavaScript to do it? If you mean doing an
>> HTTP request from within a web-page, or even a Cross Origin request,
>> in order to receive info from a 3rd-party website, then things could
>> become considerably more complicated.
>> Cheers,
>> --
>> Shaun Fryer
>> ----------------------------------------------------------
>> perl -e 'print chr for map{$_+=22}($ARGV[0])=~/(\d\d)/g' \
>>         52959394107588899482799210587992861082757785799222
>> ----------------------------------------------------------
>> On Tue, Oct 9, 2012 at 5:48 PM, Antonio Sun <antoniosun at lavabit.com>
>> wrote:
>> > Hi,
>> >
>> > I know it's kind of OT, but since we have a lot of web experts here, let
>> > me
>> > try my luck here first.
>> >
>> > I have zero knowledge of Javascript, I'm wondering if you could give me
>> > a
>> > big favor to show me how to watch for certain keyword from a web page
>> > using
>> > Javascript.
>> >
>> > Basically, I have a slow updating web page, and I need a client side
>> > Javascript to watch for a specific keyword in that page and pop up an
>> > window
>> > if the keyword is found.
>> >
>> > As I have zero knowledge of Javascript, I hope that your answer is as
>> > complete as possible.
>> >
>> > Thanks a lot in advance
>> >
>> > Antonio
>> >
>> >
>> > _______________________________________________
>> > toronto-pm mailing list
>> > toronto-pm at pm.org
>> > http://mail.pm.org/mailman/listinfo/toronto-pm
>> >

More information about the toronto-pm mailing list