Accessing a local variable (timer ID)

J

Joe

Hi,

I am trying to alter the refresh rate of an online webpage in a webbrowser
control using MFC. However the Timer ID is stored in a local variable and I
don't know how to access it. Is there a technique in Javascript that I might
be able to use/adapt?

I have a timer set within a prototype thus:

;HControl.prototype.setFLTimeout = function() {
var oFLTimeout = setTimeout("hCtrl.mkView.reloadFL();", iFLTimeout);
}

But the timer Id oFLTimeout is local so, once the page is loaded how can I
access and stop the timer to prevent the page refreshing (or perhaps "reset"
it to my own bespoke rate)?
The only way I know how is using clearTimeout(), however this method
requires the timer ID.

Can I "list" all the timers somehow?

I really am stumped and would like some advise on how I can progress.

Thanks
 
L

Lee

Joe said:
Hi,

I am trying to alter the refresh rate of an online webpage in a webbrowser
control using MFC. However the Timer ID is stored in a local variable and I
don't know how to access it. Is there a technique in Javascript that I might
be able to use/adapt?

Stop trying to cheat on whatever timed test it is
that you're trying to hack.
 
E

Evertjan.

Joe wrote on 13 sep 2004 in comp.lang.javascript:
I am trying to alter the refresh rate of an online webpage in a
webbrowser control using MFC. However the Timer ID is stored in a
local variable and I don't know how to access it. Is there a technique
in Javascript that I might be able to use/adapt?

I have a timer set within a prototype thus:

;HControl.prototype.setFLTimeout = function() {
var oFLTimeout = setTimeout("hCtrl.mkView.reloadFL();", iFLTimeout);

So use a global variable.

You are the boss of the code, aren't you?

===

var oFLTimeout;

HControl.prototype.setFLTimeout = function() {
oFLTimeout = setTimeout("hCtrl.mkView.reloadFL();", iFLTimeout);

===
 
J

Joe

So use a global variable.
You are the boss of the code, aren't you?

No, I'm not!

Perhaps I wasn't clear enough, I said "online webpage" in other words I'm
downloading the page and its scripts and I want to inhibit/change the page
refresh timer.

Thanks
 
E

Evertjan.

Joe wrote on 13 sep 2004 in comp.lang.javascript:
No, I'm not!

Perhaps I wasn't clear enough, I said "online webpage" in other words
I'm downloading the page and its scripts and I want to inhibit/change
the page refresh timer.

Indeed you were not very clear.

So open the page,
go to view source,
change the code and save the local file,
then execute this local file,
if necessary after adding:
<base href="http://the original url here"> in the <head> section.
 
J

Joe

Evertjan. said:
Joe wrote on 13 sep 2004 in comp.lang.javascript:

Indeed you were not very clear.

So open the page,
go to view source,
change the code and save the local file,
then execute this local file,
if necessary after adding:
<base href="http://the original url here"> in the <head> section.

Well I'm still not being very clear:)

I want to download the web page into my browser control.
I want to then execute a "function" within my MFC program through the
script interface which will allow me to "automatically" adjust the refresh
rate by altering the script function dynamically.

If the timerID is a global variable I can do it.

However as it is a local variable I can't.

"Manually" changing the page scripts isn't an option.
 
J

Joe

Lee said:
Joe said:

Stop trying to cheat on whatever timed test it is
that you're trying to hack.


Thanks Lee, very useful. Of course, I'm not "cheating" anything.

Have you any constructive comments to make which might actually help me out?
 
L

Lee

Joe said:
Thanks Lee, very useful. Of course, I'm not "cheating" anything.

You're welcome.

It's not your page. Somebody put a timer there for a
reason. You're trying to change it. That fits my
definition of cheating.

If it happens not to be a test, posting a solution (if
one existed) would allow others to cheat on such tests.
 
E

Evertjan.

Joe wrote on 13 sep 2004 in comp.lang.javascript:
Well I'm still not being very clear:)

I want to download the web page into my browser control.

What is a "browser control"?
I want to then execute a "function" within my MFC program through the
script interface which will allow me to "automatically" adjust the
refresh rate by altering the script function dynamically.

If the timerID is a global variable I can do it.

However as it is a local variable I can't.

"Manually" changing the page scripts isn't an option.

Changing the page by script should be possible.

I suppose you want to do some data mining.

Like this?

function getUrl(url) {
var http = new ActiveXObject("microsoft.xmlhttp");
http.open("GET",url,false);
http.send();
return http.responseText;
}

When the content of the file is in a local variable as a string,
you can replace parts of that string with multiple regex replace.

t = getUrl('http://yourTargettedWEBsource.com/')

t = t.replace(/;HControl.prototype/,
'var oFLTimeout\n;HControl.prototype')
t = t.replace(/var oFLTimeout/,'oFLTimeout')


After that you can execute the string as if it were a http file.

[How? I have to think about that ;-) ]
 
J

Joe

Lee said:
Joe said:

You're welcome.

It's not your page. Somebody put a timer there for a
reason. You're trying to change it. That fits my
definition of cheating.
If it happens not to be a test, posting a solution (if
one existed) would allow others to cheat on such tests.

So you're posting smart-arse comments from baseless assumptions when you
have no idea at all why I want to do what I'm asking.

That fits my definition of a ******* ******.

Have a nice day.
 
J

Joe

Evertjan. said:
Joe wrote on 13 sep 2004 in comp.lang.javascript:


What is a "browser control"?

Microsofts WebBrowser Control.
By downloading a page into that I can get "programatic" access to the
documents properties and objects, scripts etc and do some "bespoke"
operations on them (hopefully) such as altering the refresh rate. It also
allows you to execute javascript functions - "standard" such as
ClearTimeout() and user defined, but as the timerID is only defined locally
in the prototype settimer function I gave in my initial post I can't find
it.

Here's a refrence if you're interested:
http://msdn.microsoft.com/workshop/browser/webbrowser/webbrowser.asp

Changing the page by script should be possible.
I suppose you want to do some data mining.

Sort of.
But really I don't want unecessary refreshes clogging up bandwidth. Also any
solution might help me learn a nice way into the scripts.
Like this?

function getUrl(url) {
var http = new ActiveXObject("microsoft.xmlhttp");
http.open("GET",url,false);
http.send();
return http.responseText;
}

Maybe. With a webbrowser control its possible build that text as a function
and execute it as javascript. I'm sure you can in other languages but I'm
familiar with MFC (not an expert with the WBC or javascript though).

For instance I've managed to alter the timer rate and set up a new timer for
the page.
However, all this does is add a new timer in addition to the old so I end up
with both timers refreshing the page.

When the content of the file is in a local variable as a string,
you can replace parts of that string with multiple regex replace.

t = getUrl('http://yourTargettedWEBsource.com/')

t = t.replace(/;HControl.prototype/,
'var oFLTimeout\n;HControl.prototype')
t = t.replace(/var oFLTimeout/,'oFLTimeout')


After that you can execute the string as if it were a http file.

[How? I have to think about that ;-) ]

OK. Whatever ideas you may come up with I will obviously have to convert to
run in the WBC but thats my problem ;) - I just need a way forward.

Will the timer be prevented from running by changing the text, given that
the script may have been executed and the timer set up before the text is
altered?

I'm not sure how I can change any script after it is downloaded but before
it runs in a WBC. If its possible then I could just change the timer delay
variable to be whatever rate I want - although this would then be fixed for
the life of the WBC.

An ideal solution would be to delete the existing timer so that I can set up
a new timer to refresh at any rate I wish.

But any ideas appreciated.
 
L

Lee

Joe said:
So you're posting smart-arse comments from baseless assumptions when you
have no idea at all why I want to do what I'm asking.

That fits my definition of a ******* ******.

What part of my comments qualify as "smart-arse"?

No, you don't seem to read well. I do have a base for my
assumptions. You're trying to change the functionality of
somebody else's web page. That a pretty substantial base.
If you've got some justification, it's up to you to present
it, if you expect help.

I've also said that completely regardless of why you want to
do what you're asking for, it would be irresponsible to post
a solution (if one existed).
 
L

Lasse Reichstein Nielsen

Joe said:
I want to download the web page into my browser control.
I want to then execute a "function" within my MFC program through the
script interface which will allow me to "automatically" adjust the refresh
rate by altering the script function dynamically.

I recommend changing the content of the page by intercepting the download
of the page, and then change the page before giving it to the control (if
intercepting is possible). You can then change the page to make the local
variable global, or something else.
If the timerID is a global variable I can do it.
However as it is a local variable I can't.
Correct.

"Manually" changing the page scripts isn't an option.

Are you sure? It could be easier.

Also, getting the id of the timeout won't help you a lot anyway. All
you can do is cancel that one timeout. A better way would be to
replace the "setTimeout" with your own version, that calls the
original. Something like executing this script:

---
var oldSetTimeout = setTimeout;
var myOverrideTime;
var myLatestTimeout;
setTimeout = new function(arg,time) {
return (myLatestTimeout = oldSetTimeout(arg, myOverrideTime || time);
};
 
J

Joe

Lasse Reichstein Nielsen said:
I recommend changing the content of the page by intercepting the download
of the page, and then change the page before giving it to the control (if
intercepting is possible). You can then change the page to make the local
variable global, or something else.

Hello Lasse.

I've been investigating this for some time but haven't found out how to do
it through a WebBrowser Control - of course doesn't mean it can't easily be
done ;)

Are you sure? It could be easier.

Well, depends on what one means by "manually". I want to run the program
automatically without having to be present.

Also, getting the id of the timeout won't help you a lot anyway. All
you can do is cancel that one timeout. A better way would be to
replace the "setTimeout" with your own version, that calls the
original. Something like executing this script:

---
var oldSetTimeout = setTimeout;
var myOverrideTime;
var myLatestTimeout;
setTimeout = new function(arg,time) {
return (myLatestTimeout = oldSetTimeout(arg, myOverrideTime || time);
};

Again, this is dependent on me being able to change the scripts before
execution which I'm trying to work out how to do.

Thanks
 
J

Joe

Lee said:
Joe said:

What part of my comments qualify as "smart-arse"?

No, you don't seem to read well. I do have a base for my
assumptions. You're trying to change the functionality of
somebody else's web page. That a pretty substantial base.
If you've got some justification, it's up to you to present
it, if you expect help.

I've also said that completely regardless of why you want to
do what you're asking for, it would be irresponsible to post
a solution (if one existed).

Bye
 
L

Lasse Reichstein Nielsen

Joe said:
Again, this is dependent on me being able to change the scripts before
execution which I'm trying to work out how to do.

Ok. I don't have any experience with the MSHTML component, so I'll just
make some random guesses :)

Could you put the component into edit mode before loading the page?
Then you could use the WYSIWYG editing mode to insert or change content
before removing edit mode again. I don't know if that would prevent
scripts from running, or if it is possible to select edit mode before
loading the page.

Could you add a C++ event handler for the window's onload event?
(<URL:http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/prog_browser_node_entry.asp>
says the event "Fires immediately after the browser loads the object.". That
might be before the page's onload script, and it would be soon enough
to change the functionality of setTimeout).

Intercepting the page load might be possible using
<URL:http://msdn.microsoft.com/workshop/browser/ext/overview/downloadmgr.asp>

Good luck.
/L
 
E

Evertjan.

Joe wrote on 13 sep 2004 in comp.lang.javascript:
Will the timer be prevented from running by changing the text, given that
the script may have been executed and the timer set up before the text is
altered?

No the script will not execut ig you xmlhttp-get it to a string.
Microsofts WebBrowser Control.

Sorry, I do not think we are talking on the same level.
This is not part of my javascript knowledge.
 
J

Joe

Lasse Reichstein Nielsen said:
Ok. I don't have any experience with the MSHTML component, so I'll just
make some random guesses :)

Could you put the component into edit mode before loading the page?
Then you could use the WYSIWYG editing mode to insert or change content
before removing edit mode again. I don't know if that would prevent
scripts from running, or if it is possible to select edit mode before
loading the page.

Could you add a C++ event handler for the window's onload event?
(<URL:http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/pr
og_browser_node_entry.asp>
says the event "Fires immediately after the browser loads the object.". That
might be before the page's onload script, and it would be soon enough
to change the functionality of setTimeout).

Intercepting the page load might be possible using
<URL:http://msdn.microsoft.com/workshop/browser/ext/overview/downloadmgr.asp

Thanks for the pointers, though I'm not sure its as "simple" as that. Anyway
I've had enough for today ;)
 
R

Robert

Joe said:
Hi,

I am trying to alter the refresh rate of an online webpage in a webbrowser
control using MFC. However the Timer ID is stored in a local variable and I
don't know how to access it. Is there a technique in Javascript that I might
be able to use/adapt?

Functions are variables in Javascript, so replace the function with
your own by a one liner on the command line.


Let's say you have the following function.
color.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Popup</title>
<SCRIPT type="text/javascript">
var colors = 0;
var colorList = ["red","yellow","blue"];

function changeColor()
{

colors = colors % colorList.length;

document.getElementById("colorit").style.color = colorList[colors];
colors++
setTimeout("changeColor()",1500);
}

</script>
</head>
<body onload="changeColor();">
<p id="colorit">Change the color of this text.</p>
</body>
</html>



Copy the following one line into broswer command line and press enter.

( I have included two versions of the one line. The first the real one
line and the second the list of statements you will have to make into
one line. )

There may be alimit on the size of the one line file. Maybe 2k in IE.

You should see the colors displayed change. I did with Netscape 7.2
and IE 5.2 on MacOS 10.2.6.




javascript: alert("injection.."); function changeColor() { var
colorList = ["black","pink","green"]; colors = colors %
colorList.length; document.getElementById("colorit").style.color =
colorList[colors]; colors++; setTimeout("changeColor()",500); }



javascript: alert("injection..");
function changeColor() { var colorList = ["black","pink","green"];
colors = colors % colorList.length;
document.getElementById("colorit").style.color = colorList[colors];
colors++; setTimeout("changeColor()",500); }


Robert
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top