Board index » cppbuilder » get text from javascript?

get text from javascript?


2005-02-24 12:05:47 PM
cppbuilder105
Hello :)
My program downloads a php file from a site which contains an embedded
javascript function. The script displays a countdown timer on the web page.
Is it possible to get the text of the count down script which is currently
displayed on the site. I'm not certain if this is possible but you never
know.
Thanks very much for taking your time to read this and for any suggestions
or info.
 
 

Re:get text from javascript?

bcb wrote:
Quote
My program downloads a php file from a site which contains an embedded
javascript function. The script displays a countdown timer on the web page.
Is it possible to get the text of the count down script which is currently
displayed on the site.
Yes.
Is the script embedded in the resulting html source or
is it in a .js file and included ?
Hans.
 

Re:get text from javascript?

Hi Hans.
Thanks for replying.
The script is embeddeded in the resulting php file.
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
bcb wrote:

>My program downloads a php file from a site which contains an embedded
>javascript function. The script displays a countdown timer on the web
page.
>Is it possible to get the text of the count down script which is
currently
>displayed on the site.

Yes.

Is the script embedded in the resulting html source or
is it in a .js file and included ?

Hans.
 

{smallsort}

Re:get text from javascript?

The file resulting has a php extention but of html format.
"bcb" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Hans.

Thanks for replying.

The script is embeddeded in the resulting php file.
 

Re:get text from javascript?

bcb wrote:
Quote
The script is embeddeded in the resulting php file.
Get the hrmldata with a HTTP component like TIdHTTP or
TNMHTTP. You could even use TCppWebBrowser.
Then parse the data. Just look for <script>and so on.
Hans.
 

Re:get text from javascript?

Thanks Hans. I already know how to download the file but embedded in the
html file is the actual JavaScript code, not exactly what is displayed to
the public on the website itself.
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
bcb wrote:

>The script is embeddeded in the resulting php file.

Get the hrmldata with a HTTP component like TIdHTTP or
TNMHTTP. You could even use TCppWebBrowser.

Then parse the data. Just look for <script>and so on.

Hans.
 

Re:get text from javascript?

"bcb" < XXXX@XXXXX.COM >wrote in message
Quote
Thanks Hans. I already know how to download the file but
embedded in the html file is the actual JavaScript code, not
exactly what is displayed to the public on the website itself.
Sounds like you will probably have to actually execute the script in order
to know what output it produces.
Gambit
 

Re:get text from javascript?

Part of the script looks something like
if (document.all)
document.all.countDownText.innerText = secsToMins(countDownTime);
else if (document.getElementById)
document.getElementById("countDownText").innerHTML =
secsToMins(countDownTime);
would it be possible to get the value of the CountDownTime variable?
"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
bcb wrote:

>The script is embeddeded in the resulting php file.

Get the hrmldata with a HTTP component like TIdHTTP or
TNMHTTP. You could even use TCppWebBrowser.

Then parse the data. Just look for <script>and so on.

Hans.
 

Re:get text from javascript?

"bcb" < XXXX@XXXXX.COM >wrote in message
Quote
would it be possible to get the value of the CountDownTime variable?
You did not show where it is declared or assigned.
Gambit
 

Re:get text from javascript?

Hi Remy :)
Here is the piece of the html source:
the script:
<script language="JavaScript" type="Text/JavaScript">
<!--
var countDownInterval = 46;
var countDownTime = countDownInterval + 1;
if (document.all||document.getElementById)
countDown();
else
window.onload = countDown;
function countDown() {
countDownTime--;
if (countDownTime == 0) {
countDownTime = countDownInterval;
window.location.reload();
return;
}
else if (countDownTime < 5)
countDownTime = countDownTime + 00000;
if (document.all)
document.all.countDownText.innerText = secsToMins(countDownTime);
else if (document.getElementById)
document.getElementById("countDownText").innerHTML =
secsToMins(countDownTime);
counter = setTimeout("countDown()", 1000);
}
function secsToMins(theValue) {
var theMin = Math.floor(theValue / 60);
var theSec = (theValue % 60);
if (theSec < 10)
theSec = "0" + theSec;
return(theMin + ":" + theSec);
}
// -->
</script>
the part of the html source involved with actually displaying the info looks
something like,
<tr>
<td class="td01" height="63" colspan="3" valign="middle" align="center">
<br>
Count down display (<span id="countDownText"></span>)<br>
<br>
</td>
</tr>
 

Re:get text from javascript?

"bcb" < XXXX@XXXXX.COM >wrote in message
Quote
Here is the piece of the html source:
That script dynamically changes the page's text 47 times. Do you want to
retreive all 47 text messages that get displayed to the user?
Gambit
 

Re:get text from javascript?

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote
That script dynamically changes the page's text 47 times. Do you want to
retreive all 47 text messages that get displayed to the user?
I just need to get the first instance, then I can continue the countdown
timer using a TTimer.
 

Re:get text from javascript?

"bcb" < XXXX@XXXXX.COM >wrote in message
Quote
I just need to get the first instance, then I can continue
the countdown timer using a TTimer.
Just load the script/html into a TStringList and then locate and parse out
the lines that declare the countDownInterval and countDownTime variables.
Gambit
 

Re:get text from javascript?

Remy and Hans, thanks for taking your time to help.
Working with a TStringList is a good idea. I now see exactly how the site
code works. Got lucky the first try when trying to match the site's text
with html code, everything matched but then lead myself astray. I was using
IE's view source menu command without actually refreshing the page before
each view of the source, the countDownInterval changes with every refresh,
duh! ;) . My knowledge of html is very minute, took a while to understand
the whole page's code.
Thanks again for your time :)
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"bcb" < XXXX@XXXXX.COM >wrote in message
news:421ea351$ XXXX@XXXXX.COM ...

>I just need to get the first instance, then I can continue
>the countdown timer using a TTimer.

Just load the script/html into a TStringList and then locate and parse out
the lines that declare the countDownInterval and countDownTime variables.


Gambit