Newsgroup: it.comp.lang.javascript
Titolo: Anonymous function Scope / Add <SCRIPT> to pages

I have two Windows (WEBRC and UPage). I want to dynamically create a
function from within WEBRC, but the function is to be used by UPage.
Therefore, I would like it to be in the scope of UPage. Is there any
way of doing this? I currently use new Function() constructor on WEBRC
to create an anonymous function, but it is contained on WEBRC. I need
it contained on UPage. Is there a way to modify its scope or
dynamically create it from WEBRC on UPage?
Another way I possibly thought of doing this is to dynamically add a
SCRIPT block to UPage, and adding the functions in there. Please note
that the page loaded within UPage cannot be permantely modified, so
therefore I am trying to use JScript on WEBRC to temporarily modify
UPage. Is there any way to do this?
I hope this makes sense and there is a way to accomplish what I want
done.
I appreciate all and any help.
Thanks,
Chad Waldman
chad.w...@usa.net
Sent via Deja.com 
http://www.deja.com/
Before you buy.

 dynamically create it from WEBRC on UPage?
If yourFunction() is contained in WEBRC, you can simply say
top.UPage.yourFunction = top.WEBRC.yourFunction;
after yourFunction() is created.
--
Thor Larholm

,

Ok, that sounds logical, however it leads to another question. What I am
doing is actually overwriting the events on UPage. In order to do that, I
create a new function on WEBRC and assign the event to that function.
The event is pointing to the anonymous function on WEBRC, not to the
copy on UPage. Now, I guess I can make the copy and assign the event to
the copied function, but then this leads me to one more question. I just
created a function using hte Function constructor. There are now two
copies of that function, one on WEBRC and one on UPage. I don't need the
copy on WEBRC. For memory reasons, can I somehow remove the copy
on WEBRC, after I made a copy of it on UPage?
Chad


 wrote in message
news:8irdse$rfh$1...@nnrp1.deja.com...

First of all, the best solution would be to simply create the function on
UPage to begin with.
Just delete the function.
delete top.UPage.yourFunction;
--
Thor Larholm

,

Thank you. I would like to create the function to begin with on UPage,
but I need to do so from WEBRC. WEBRC contains functions which overlook
UPage, well at least the idea is that is launches a window which loads
a webpage, then modifies its events to send info back to WEBRC.
If I can create the function on UPage from WEBRC, other than creating
it first on WEBRC and copying it over, that would be great. Please
share if you know how.


 wrote in message
news:8irm4t$1jq$1...@nnrp1.deja.com...

Well, you are already using the new Function constructor, so instead of
yourFunction = new Function(...)
you could just say
top.UPage.yourFunction = new Function(...)
--
Thor Larholm

,

I tried that, but apparently it creates an anonymous function on WEBRC
and sets top.UPage.yourFunction to point to that anonymous function.
The way I figured this out was by putting an alert(
self.name
) in the
created function, but sure enough, when the function was called, it
alerted WEBRC instead of UPage. :(
Do you know of any other way to do this?
I appreciate all your help and time.
Chad Waldman
